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

How to handle mixed content errors on playwright #2540

Closed
robertsLando opened this issue Nov 6, 2023 · 6 comments
Closed

How to handle mixed content errors on playwright #2540

robertsLando opened this issue Nov 6, 2023 · 6 comments

Comments

@robertsLando
Copy link

robertsLando commented Nov 6, 2023

When I run tests using playwrightLauncher tests are not working, what I'm tring to do is to connect to a wss that is not allowed from a non secure context. How can I make it work?

There should be an option on playwright named ignoreHTTPSErrors that should do the trick but I don't understand where I should use it: https://playwright.dev/docs/api/class-browser#browser-new-context

@bashmish
Copy link
Member

bashmish commented Nov 6, 2023

This might be the way, can you play with it?

// @web/test-runner-playwright/src/PlaywrightLauncher.ts
export type CreateBrowserContextFn = (args: CreateArgs) => BrowserContext | Promise<BrowserContext>;

export class PlaywrightLauncher implements BrowserLauncher {
  // ...
  private createBrowserContextFn: CreateBrowserContextFn;
  // ...
}

You can pass it via playwrightLauncher argument { createBrowserContext }.

@robertsLando
Copy link
Author

robertsLando commented Nov 6, 2023

Thanks for the hint:

function createBrowserContext({ browser, config }) {

    // ignore HTTPS errors
    const context = browser.newContext({
        ignoreHTTPSErrors: true
    })
    return context

}

....

export default {
    // https://modern-web.dev/docs/test-runner/browser-launchers/playwright/#testing-multiple-browsers
    // Requires: @web/test-runner-playwright
    browsers: [
        playwrightLauncher({
            product: 'chromium', createBrowserContext
        }), // { headless: false, devtools: true }  }),
        playwrightLauncher({ product: 'firefox', createBrowserContext }),
        playwrightLauncher({ product: 'webkit', createBrowserContext }),
    ],
....

This actually works for chromium but not for firefox and webkit, will do some more tests to dfind out how to make others working

@robertsLando
Copy link
Author

It should work also for firefox and webkit based on docs but I them are not working as expected.... any other hint?

@robertsLando
Copy link
Author

robertsLando commented Nov 7, 2023

Ok fixed. The solution described above was correct I only had to do test in series instead of parallel.

This can be closed but I suggest to add an example on docs with the createBrowserContext like this.

Thanks again for the support given so far 🙏🏼

@bashmish
Copy link
Member

bashmish commented Nov 7, 2023

Ok fixed. The solution described above was correct I only had to do test in series instead of parallel.

did you have to set "concurrent: 1"? if so, then it might be related to a recent change in Chrome which cuts resources in inactive tabs, which are heavily used by WTR, so that many tests don't work in there
that's another issue which we don't have a solution for, so we recommend for now to disable concurrency

@robertsLando
Copy link
Author

robertsLando commented Nov 7, 2023

Nope I simply had to wait for ws tests to end before running wss tests, at start I was just starting both one after the other:

https://github.com/mqttjs/MQTT.js/blob/main/test/browser/test.js#L60

Tests are passing: https://github.com/mqttjs/MQTT.js/actions/runs/6782443335/job/18434666671#step:6:33 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants