Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] page.route not working properly #38

Closed
aesyondu opened this issue Feb 17, 2020 · 7 comments
Closed

[BUG] page.route not working properly #38

aesyondu opened this issue Feb 17, 2020 · 7 comments
Labels
bug Something isn't working

Comments

@aesyondu
Copy link
Contributor

Context:

  • Jest-Playwright Version: 0.0.9
  • Playwright Version: 0.11.1
  • Operating System: Mac OS X 10.14.6
  • Extra: node@11.15.0 npm@6.7.0

Code Snippet

    /** works **/
    // const { chromium } = require("playwright")
    // const mybrowser = await chromium.launch()
    // const mycontext = await mybrowser.newContext()
    // const mypage = await mycontext.newPage()
    // await mypage.route(/\.(png|jpeg|jpg)$/, request => request.abort());
    // await mypage.goto(baseUrl)

    /** doesn't work, throws error **/
    await page.route(/\.(png|jpeg|jpg)$/, request => request.abort());
    await page.goto(baseUrl)

Describe the bug

page.route throws the error below, works fine when instantiating playwright manually:

  console.error node_modules/jest-jasmine2/build/jasmine/Env.js:248
    Unhandled error

  console.error node_modules/jest-jasmine2/build/jasmine/Env.js:249
    Error: url parameter should be string, RegExp or function
        at Object.assert (/Users/aes/projects/amber/node_modules/playwright-core/lib/helper.js:196:15)
        at Object.urlMatches (/Users/aes/projects/amber/node_modules/playwright-core/lib/platform.js:206:14)
        at Page._requestStarted (/Users/aes/projects/amber/node_modules/playwright-core/lib/page.js:315:26)
        at FrameManager.requestStarted (/Users/aes/projects/amber/node_modules/playwright-core/lib/frames.js:145:24)
        at CRNetworkManager._onRequest (/Users/aes/projects/amber/node_modules/playwright-core/lib/chromium/crNetworkManager.js:169:34)
        at CRNetworkManager._onRequestPaused (/Users/aes/projects/amber/node_modules/playwright-core/lib/chromium/crNetworkManager.js:144:18)
        at CRSession.emit (events.js:193:13)
        at Promise.resolve.then (/Users/aes/projects/amber/node_modules/playwright-core/lib/chromium/crConnection.js:135:47)
@mmarkelov
Copy link
Member

@aesyondu hm! This is strange, I'm not sure what can be wrong with it.
It seems be OK when I'm using string with it:

    it('this is the second test', async () => {
        await page.route('**/*.{png,jpg,jpeg}', request => request.abort());
        await page.goto('https://example.com')
    })

Looks like instanceof RegExp for passed regexp return false.
I'll try to find out why it is happend

@mmarkelov mmarkelov added the bug Something isn't working label Feb 17, 2020
@aesyondu
Copy link
Contributor Author

How is this possible :o

image

image

@aesyondu
Copy link
Contributor Author

Umm, what...

image

@aesyondu
Copy link
Contributor Author

Using:

    const { chromium } = require("playwright")
    const mybrowser = await chromium.launch()
    const mycontext = await mybrowser.newContext()
    const mypage = await mycontext.newPage()
    await mypage.route(/\.(png|jpeg|jpg)$/, request => request.abort());
    await mypage.goto(baseUrl)

image

@mmarkelov
Copy link
Member

@aesyondu I suppose it came from jest, but actually I'm not sure. It's very confusing

@aesyondu
Copy link
Contributor Author

Gottem... hahaha. I will try to make a pull request to playwright.

  if (match instanceof RegExp || match.constructor.name == "RegExp")
    return match.test(urlString);

https://stackoverflow.com/questions/4339288/typeof-for-regexp#comment4724685_4339350

image

@mxschmitt
Copy link
Collaborator

Closed since the upstream PR looks like it was merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants