-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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] Mocking the server in chromium only works if server is reachable #2201
Comments
I tried to reproduce the issue and for me it is working as expected, full code: const playwright = require("playwright");
(async () => {
for (const browserType of ['chromium', 'webkit', 'firefox']) {
const browser = await playwright[browserType].launch();
const page = await browser.newPage();
page.route('**/cars?**', async route => {
route.fulfill({
contentType: 'application/json',
headers: { 'access-control-allow-origin': '*' },
status: 200,
body: JSON.stringify(["BMW", "Tesla"]),
})
})
const resp = await page.evaluate(async () => await (await fetch("https://10.10.10.1/cars?type=foobar")).json())
console.log(resp)
await browser.close();
}
})(); Interactive: https://try.playwright.tech/?s=trqt9 Could you try to use |
@adi-wan thank you for the warm words!
@adi-wan I can't reproduce this either. Can you please share a full repro? Here's my attempt: const playwright = require('playwright');
(async () => {
for (const browserType of ['chromium', 'webkit', 'firefox']) {
const browser = await playwright[browserType].launch();
const page = await browser.newPage();
page.route('**/*.json', async route => {
route.fulfill({
contentType: 'application/json',
headers: { 'access-control-allow-origin': '*' },
status: 200,
body: JSON.stringify(["BMW", "Tesla"]),
})
})
await page.goto('https://thisissomenonexistentwebsite.com/cars.json');
console.log(await page.evaluate(() => document.documentElement.innerHTML));
await browser.close();
}
})(); |
Closing as not-repeatable. Please feel free to reopen. |
Context:
Code Snippet
Describe the bug
First of all: Thank you for this absolutely amazing framework!
I am using Playwright together with CodeceptJs for functional and integration tests. For my integration tests I try to mock the server with Playwright. The snippet shows a brief example of this. But when using Chromium and not running an http server on the side that normally would receive these requests, this does not work. I get this error message:
When running an http server on the side, it works and the server does not receive any (http) requests. I also tried this with Firefox. Here everything works as expected. No need for running a server on the side.
The text was updated successfully, but these errors were encountered: