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.

When open a new tab, some network events are skipped.

See original GitHub issue

When 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:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Dry7commented, Jan 9, 2018

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

1reaction
cyrus-andcommented, Jan 9, 2018

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 with await popup.Network.enable();.

The solution would be to pause the target on start:

Target.setAutoAttach({
    autoAttach: true,
    waitForDebuggerOnStart: true
});

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:

Controls whether to automatically attach to new targets which are considered to be related to this one.

Maybe a popup window is not considered to be related to its opener in this context.

Read more comments on GitHub >

github_iconTop 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 >

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