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

CDPSession problem - no clean way to remove and add event listeners using results from DOMDebugger.getEventListeners #5319

Closed
timparker183 opened this issue Jan 17, 2020 · 4 comments

Comments

@timparker183
Copy link

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: 2.0.0, Chromium 79
  • Platform / OS version: AWS Lambda
  • URLs (if applicable):
  • Node.js version: 12.x

What steps will reproduce the problem?

browser = await chromium.puppeteer.launch({
args: chromium.args,
defaultViewport: chromium.defaultViewport,
executablePath: await chromium.executablePath,
headless: chromium.headless
});

let page = await browser.newPage();

let viewportSize = {width: 1920, height: 1080};
await page.setViewport(viewportSize);

let result= await page.goto('https://www.dpreview.com/archive/2019/12',{timeout:30000,waitUntil:'networkidle0'});

let client = await page.target().createCDPSession();

let wHandle = await client.send("Runtime.evaluate", {expression: "window"});
console.log(wHandle);
let listeners = await client.send("DOMDebugger.getEventListeners", {objectId:wHandle.objectId});
console.log(listeners);

What is the expected result?
I expect to get a collection of listener objects (or at least not an error - the page in the example above replaces a non-public page which has 'resize' events I need to save/kill/restore as a way of working around problems described here: #5300)

What happens instead?
DOMDebugger.getEventListeners call results in an error:

Protocol error (DOMDebugger.getEventListeners): Invalid parameters objectId: string value expected

@timparker183 timparker183 changed the title CDPSession problems CDPSession problem - DOMDebugger.getEventListeners errors out with objectId value from Runtime.evaluate Jan 17, 2020
@timparker183
Copy link
Author

The failure here is pilot error - wHandle is a struct with a single member 'result', which contains the expected contents...

however... the problem now morphs into a feature request - I need to take the resulting items and use them in removeEventListener() and addEventListener() calls - the API has methods to add and remove event breakpoints, but not the listeners themselves.

What I'm trying to implement is the equivalent of these two methods (again, see issue 5300 - this is an attempted work-around to viewport problems in doing a full-page capture)

The plan here is to do something like...

setViewport (real size)
page.goto(target)

__killResizeEvents()
setViewport (actual rendered size of target)
take screenshot
setViewport(restore real size)
__restoreResizeEvents()

==================
function __killResizeEvents()
{
var eventArray = getEventListeners(window).resize;

if (eventArray)
{
	for (let i = 0; i < eventArray.length; i = 1 + i)
	{

// console.log("removing event handler " + i);
window.removeEventListener('resize',eventArray[i].listener);
}
}

return eventArray;

}

function __restoreResizeEvents(eventArray)
{
if (eventArray)
{
for (let i = 0; i < eventArray.length; i = 1 + i)
{
// console.log("restoring event handler " + i);
window.addEventListener('resize',eventArray[i].listener);
}
}
}

===========
the CDP interface gives back a single array with everything instead of a structure with arrays for each type - so the resulting code can't be a direct translation (i.e. I'd have to loop over everything and pick out only the 'resize' items - no big deal)

but.. that still doesn't give me something I can call removeEventListener() or addEventListener() with.

@timparker183 timparker183 changed the title CDPSession problem - DOMDebugger.getEventListeners errors out with objectId value from Runtime.evaluate CDPSession problem - no clean way to remove and add event listeners using results from DOMDebugger.getEventListeners Jan 21, 2020
@TimotheeJeannin
Copy link

Hi @timparker183. Did you find a solution to your issue?

@stale
Copy link

stale bot commented Jun 24, 2022

We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days.

@stale stale bot added the unconfirmed label Jun 24, 2022
@stale
Copy link

stale bot commented Jul 24, 2022

We are closing this issue. If the issue still persists in the latest version of Puppeteer, please reopen the issue and update the description. We will try our best to accomodate it!

@stale stale bot closed this as completed Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants