[BUG] Cannot waitForResponse in a background page
See original GitHub issueContext:
- Playwright Version: [what Playwright version do you use?] 1.16
- Operating System: [e.g. Windows, Linux or Mac] Mac
- Node.js version: [e.g. 12.22, 14.6] 14.18
- Browser: [e.g. All, Chromium, Firefox, WebKit] Chromium
Code Snippet
background.js
chrome.runtime.onMessage.addListener(() => {
fetch(`https://google.com`).then(console.log).catch(console.error)
})
inject.js
const button = document.createElement('button')
button.innerText = 'Click me'
button.id = `injectedButton`
button.onclick = () => chrome.runtime.sendMessage({})
document.documentElement.appendChild(button)
const { chromium } = require('playwright-chromium')
const path = require('path')
;(async () => {
const EXTENSION_PATH = path.resolve('./ext')
const context = await chromium.launchPersistentContext(`userDataDir`, {
defaultViewport: null,
headless: false,
timeout: 0,
devtools: true,
args: [
`--load-extension=${EXTENSION_PATH}`,
`--disable-extensions-except=${EXTENSION_PATH}`,
],
})
let [backgroundPage] = context.backgroundPages()
if (!backgroundPage) {
backgroundPage = await context.waitForEvent('backgroundpage')
}
const page = await context.newPage()
await page.goto(`chrome://inspect/#extensions`)
await page.click(`#extensions-list > div > div > div > div.actions > span`)
await page.goto('https://google.com/', { waitUntil: `networkidle` })
const [response] = await Promise.all([
backgroundPage.waitForResponse(() => true, { timeout: 15 * 1000 }),
page.click('#injectedButton', { timeout: 15 * 1000 }),
])
console.log('response', response)
})()
process.on(`unhandledRejection`, console.log)
Describe the bug
I am trying to test an extension. I want to be able to check that a request is being sent once I perform an action. I used to be able to listen for backgroundPage request and response. But it now times out 😦
The snippets show a playwright script starting chromium with an extension. The extension adds a button. This button triggers a request on click.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (3 by maintainers)
Top Results From Across the Web
How to wait for JavaScript to finish in playwright - Stack Overflow
First I fill the text and then click on tab key to invoke the JavaScript that formats the value in the element. await...
Read more >Puppeteer documentation - DevDocs
Puppeteer methods might throw errors if they are unable to fulfill a request. For example, page.waitForSelector(selector[, options]) might fail if the selector ...
Read more >Reliably Send an HTTP Request as a User Leaves a Page
Perhaps the most obvious approach to avoid this problem is, as much as possible, to delay the user action until the request returns...
Read more >88373 - Chrome extension background page XHR forbidden ...
Does this problem only occur with the Matlab extension, or are the other developer omnibox extensions affected? Do you have any other extensions ......
Read more >How to increase the timeout for a REST response? - ServiceNow
Here is the code I'm using (testing through Scripts – Background): ... system property to false and use the waitForResponse() method to set...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Typo, should be
1.17.0-rc1
I have the same issue:
page.waitForResponse
never resolves for urls different from the current page url. I had to to use the following workaround to get a response:Any news about this bug?
Context: