When open a new tab, some network events are skipped.
See original GitHub issueWhen I click on a page http://getresto.gifts48.ru/1/
A window opens with the following redirect chain:
http://getresto.gifts48.ru/1/popup1.php http://getresto.gifts48.ru/1/popup2.php http://getresto.gifts48.ru/1/popup3.php http://getresto.gifts48.ru/1/popup4.php http://getresto.gifts48.ru/1/popup5.html http://getresto.gifts48.ru/1/popup6.html http://getresto.gifts48.ru/1/popup7.html http://getresto.gifts48.ru/1/popup8.html
I’m trying to collect this chain with this code
const CDP = require('chrome-remote-interface');
CDP(async (client) => {
const {Network, Page, Target} = client;
Network.requestWillBeSent(({request, redirectResponse}) => {
console.log((redirectResponse || {}).url + ' -> ' + request.url);
});
Target.targetCreated((params) => {
if(params.targetInfo.type != "page") {
return;
}
const {targetId} = params.targetInfo;
const findTarget = (targets) => {
return targets.find(target => target.id === targetId);
};
CDP({target: findTarget}, async (popup) => {
popup.Network.requestWillBeSent(({request, redirectResponse}) => {
console.log((redirectResponse || {}).url + ' -> ' + request.url);
});
await popup.Network.enable();
});
});
try {
await Target.setDiscoverTargets({discover: true});
await Network.enable();
await Page.enable();
await Page.navigate({url: 'http://getresto.gifts48.ru/1/'});
await Page.loadEventFired();
clickPage(client);
} catch (err) {
console.error(err);
} finally {
// client.close();
}
}).on('error', (err) => {
console.error(err);
});
function clickPage(client) {
const options = {
x: 100,
y: 100,
button: 'left',
clickCount: 1
};
Promise.resolve().then(() => {
options.type = 'mousePressed';
return client.Input.dispatchMouseEvent(options);
}).then(() => {
options.type = 'mouseReleased';
return client.Input.dispatchMouseEvent(options);
}).catch((err) => {
console.error(err);
});
}
But the first three pages are missing. How can I fix this?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
link with target="_blank" does not open in new tab in Chrome
I am using a chromium browser. Works for me. So apparently it is an effect of whatever google adds to the fine chromium...
Read more >Issues: Find and fix problems - Chrome Developers
Use the Issues Tab to find and fix problems with your website.
Read more >Window.open() - Web APIs | MDN
If popup is not enabled, and there are no window features declared, the new browsing context will be a tab. Note: Specifying any...
Read more >[ Bug] "New Tab Page" has strange behavior when Edge is ...
1. Run MS Edge. · 2. Disconnect from internet. · 3. Clear browsing data. (optional) · 4. Press F5 on the "New Tab...
Read more >Links Opening in New Tabs or Windows
WCAG guideline relating to links opening in new tabs/windows · Limit the use of links or buttons that open in new windows or...
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 FreeTop 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
Top GitHub Comments
Thanks for the help. I asked questions, maybe the developers will respond with something new. But a month ago they said that this is not yet supported. https://groups.google.com/forum/#!msg/chrome-debugging-protocol/n1FQ4Ypww6w/rb4Hf-_0BgAJ
I think this is a timing problem: when the popup window opens and the
Target.targetCreated
event fires, the loading of the page starts before allowing to register for events withawait popup.Network.enable();
.The solution would be to pause the target on start:
Then setup events and finally resume with
Runtime.runIfWaitingForDebugger
.But unfortunately this doesn’t work, even the auto-attach feature itself doesn’t seem to work. And even when the target used to perform these operations is the DevTools target (
ws://127.0.0.1:9222/devtools/browser/...
) as it is supposed to be. Plus some segmentation faults appeared during my tests. Keep in mind that this is an experimental feature, things may not work as expected or maybe this isn’t the right approach, you can try to ask this in the Google Group.The documentation says:
Maybe a popup window is not considered to be related to its opener in this context.