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

[Feature] Intercept target creation #1101

Closed
etnbrd opened this issue Feb 25, 2020 · 5 comments
Closed

[Feature] Intercept target creation #1101

etnbrd opened this issue Feb 25, 2020 · 5 comments
Assignees

Comments

@etnbrd
Copy link

etnbrd commented Feb 25, 2020

Following this issue from puppeteer, puppeteer/puppeteer#3667, I would like to know if there is a way in playwright to intercept the creation of a target.
The use case is, as in the mentioned issue, to instrument a page before its creation and evaluation (with e.g. request interception and script injection).

@pavelfeldman
Copy link
Member

You will be able to set up interception and initial scripts on the browser context. So all the popups and click navigations that open in new pages will share interception, initial scripts and emulation parameters.

Will this work for you?

@etnbrd
Copy link
Author

etnbrd commented Feb 25, 2020

The browserContext API: https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browsercontext

It's doesn't seem to be implemented yet. But what you are saying @pavelfeldman, is that it will be eventually? Or am I missing it in the API?
I guess that's what aslushnikov presented in the initial issue.
And yes, that would be perfect for our use cases 👌

@pavelfeldman
Copy link
Member

Yes, it is on its way.

@dgozman
Copy link
Contributor

dgozman commented Mar 20, 2020

We updated the API and moved/copied many methods to the BrowserContext, e.g. browserContext.route() and browserContext.addInitScript(). This should cover "setup the page" scenario and works nicely with popups and link clicks as well as pages created with context.newPage().

New APIs will be included in the next 0.12 release.

@szmarczak
Copy link
Contributor

Is it possible to actually intercept the targets? For example, asynchronously run and await Node.js code, which would be running after a response is received, but before webpage scripts are ran. The Node.js code could modify cookies, storages etc. context.addInitScript doesn't work here, because you're bound to the webpage context.

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

5 participants