question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intercept target creation

See original GitHub issue

In many ways, users want to intercept targets being created to attach and set them up.

Usecases:

  • when popup is getting opened, attach to it and enable request interception
  • when a link click opens a new page, set proper device emulation before website is getting loaded

We might be able to do this with CDP using Target.setAutoAttach and waitForDebugger option. I’d like this to be scoped to browser context though so that’s there’s a better flexibility.

The API might look like this:

await browserContext.setTargetInterception(true);
browserContext.on('targetcreated', async target => {
  if (target.type() !== 'page') {
    await target.resumeLoading();
    return;
  }
  const page = await target.page();
  await page.setViewport({width: 400, height: 400});
  await target.resumeLoading();
});

Related issues: #1378, #3648

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:63
  • Comments:23 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
saberworkscommented, Jun 18, 2019

Is there an ETA on a fix for this? Browsing pages I do not control, I am watching for the targetcreated event in order to inspect popups. When a popup occurs, there doesn’t seem to be any way for me to inspect the network requests. On main page, I can add a handler for request and requestfinished prior to a page.goto which means every network request for that page (even the initial one) can be inspected. However, if I attach request or requestfinished event handlers on the popup page, it’s already too late; the page has already started loading and the events never fire (maybe I’ll see some if the page takes a long time to load a bunch of resources, but never the initial one).

After the fact, I can get the URLs of things that loaded by inspecting the trace file, but it’s difficult to pinpoint only the ones loaded by the popup. In addition, I don’t have access to all the other goodies provided by the Request object (headers, content, etc.).

A fix or any workaround suggestion would be greatly appreciated!

6reactions
berstendcommented, Oct 15, 2020

Everyone who’s interested in seeing this fixed: Please star this chromium bug reported by Niek, so the chromium devs know there’s strong interest in getting this resolved - thanks!

https://bugs.chromium.org/p/chromium/issues/detail?id=1070568

Read more comments on GitHub >

github_iconTop Results From Across the Web

Step 4: Setting Up Your Intercept - Qualtrics
Intercepts decide what target your creative should link to, and the conditions under which the creative should appear on your website. You can...
Read more >
Puppeteer: How do I intercept requests across multiple "pages"?
One important thing for you to know is that, although a new target will be created, a PDF will be open by the...
Read more >
Intercepting requests | Checkly
Request interception enables us to observe which requests and responses are being ... would result in the target website loading without any CSS...
Read more >
A Practical Guide to Intercepting Network Requests in Cypress
With our .intercept() we have matched three different requests. To target e.g. only our POST /api/boards request, we'll write our command like this:....
Read more >
Puppeteer documentation - DevDocs
Emitted when a new target is created inside the browser context, for example when a new page is ... In order to intercept...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found