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

Provide a safe way of overriding _isPageTargetCallback #9262

Closed
oliverdunk opened this issue Nov 13, 2022 · 0 comments · Fixed by #11604
Closed

Provide a safe way of overriding _isPageTargetCallback #9262

oliverdunk opened this issue Nov 13, 2022 · 0 comments · Fixed by #11604
Assignees

Comments

@oliverdunk
Copy link

I've recently been looking in to testing WebExtensions (e.g #2486). With the action.openPopup API, it's possible to trigger the extension popup by running code from the background page. This causes a new context to load which it would be useful to be able to automate.

Using the following, it actually is possible to get a reference to the new target:

const popup = await browser.waitForTarget(
  (target) =>
    target.type() === "other" &&
    target.url() === `chrome-extension://${extensionId}${path}`
);

However, calling target.page() returns null because the type is other:

#setIsPageTargetCallback(isPageTargetCallback?: IsPageTargetCallback): void {
this.#isPageTargetCallback =
isPageTargetCallback ||
((target: Protocol.Target.TargetInfo): boolean => {
return (
target.type === 'page' ||
target.type === 'background_page' ||
target.type === 'webview'
);
});
}

Of course, this does make sense and the best solution would be accommodating extension testing in the Chrome Dev Tools protocol by returning a new "popup" type. At least one relevant issue is likely this one: https://crbug.com/1223710

In the meantime, however, removing the _isPageTargetCallback check does give you a page which can be automated! It sounds like some features are missing - #1215 (comment) - so exposing this should likely not be the default. That said, in my short amount of testing it seems to work well enough that allowing developers a way of experimenting with this functionality without needing to entirely fork Puppeteer may be desirable.

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

Successfully merging a pull request may close this issue.

2 participants