Is MSW in the browser able to handle form submissions and page navigation? #1578
Replies: 1 comment
-
Hi, @ScubaDaniel. Those are great questions. Can MSW handle form submits?No. The Service Worker API does not intercept form submits. At least, I wasn't able to find any mention or example of this by briefly scanning the spec/search results. Service Workers are primarily meant for intercepting async resources, such as those requested by Can MSW page navigation?Service Workers can intercept page navigation since a However, MSW always bypasses such navigation requests intentionally. This is done so that you don't serve a mock response for an HTML page accidentally, breaking your website. Those initial requests for HTML, JS, and CSS (basically, any static resources on initial load) are always bypassed and you cannot affect them with MSW in any way. Here's where they are bypassed: Lines 96 to 99 in 156e80b You can modify the worker script, removing this line, if that's what your requirements ask of you. |
Beta Was this translation helpful? Give feedback.
-
I'm using Storybook, Playwright, and MSW (browser) together for integration tests. When I try to handle a POST form submission (not through
fetch
), nothing is caught. Is this expected? It'd be nice if those could be handled.Additionally, I use
page.goto
in Playwright, but it seems the MSW handlers don't handle those requests. Is this a limitation on the browser implementation?Beta Was this translation helpful? Give feedback.
All reactions