Playwright integration or runtime overrides solution #2404
Unanswered
kristojorg
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all, I am wondering if anyone has a working example of using MSW with Playwright and enabling runtime handler overrides? I have previously had this working using playwright-msw, but that library appears to be unmaintained and has stopped working for me. I have also taken a look at various examples such at the remix example, but none of the example I could find actually use runtime overrides.
I have seen @kettanaito mention that runtime overrides can be enabled by exposing
msw
on thewindow
object of the app, then usingpage.evaluate(() => { msw.worker.use(...) })
in a test. However, the service worker is not registered until the page runs, at which point my application is also already making network requests I would like to mock.The
playwright-msw
package avoided this issue by transforming msw handlers into Playwright'sPage.route()
format. Playwright is then using the Chrome Devtools protocol to intercept requests rather than setting up a service worker, which means the handlers can be registered before the page is actually requested or loaded.I'm wondering if anyone has found a working solution to this? If not, shall we open a discussion about how MSW could integrate directly with playwright?
Beta Was this translation helpful? Give feedback.
All reactions