astral icon indicating copy to clipboard operation
astral copied to clipboard

Work on existing pages

Open lucafabbian opened this issue 1 year ago • 4 comments

I would like to work on already opened pages rather than using await browser.newPage every time. Especially useful when testing astral from deno jupyter notebooks, since those are sometimes subjected to crashes.

lucafabbian avatar Nov 05 '24 14:11 lucafabbian

This sounds like it might be similar to what's happening in #86

It seems to be that the default behavior is to open a new window when starting a session

chaosharmonic avatar Nov 27 '24 00:11 chaosharmonic

@lino-levan , I came up with a solution for that. I would like to implement two new methods on the "browser" class.

browser.listAllPages() that returns the content of http://localhost:9222/json

browser.importExistingPage(page obj or websocket url) that checks if the page already exists amongst browser.pages[] or otherwise starts a new websocket link

If you like the idea, I can come up with a PR

lucafabbian avatar Dec 21 '24 11:12 lucafabbian

I'd be curious to look at precedent. How do puppeteer/playwright deal with this? Not against it though.

lino-levan avatar Dec 21 '24 14:12 lino-levan

The correct approach is to auto-import all pages on browser boot – I think – it's at least a better default than what we have now. This will still lose pages if you have parallel connections opening and closing pages though. I'll wait until someone complains about that with a solid motivating usecase.

lino-levan avatar May 02 '25 14:05 lino-levan