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

Return data from sandbox to background #5

Open
bestplay9384 opened this issue Aug 5, 2022 · 3 comments
Open

Return data from sandbox to background #5

bestplay9384 opened this issue Aug 5, 2022 · 3 comments

Comments

@bestplay9384
Copy link

Hey,

As far as i understand from source only CDP Events are passed to background from sandbox. Is there any way to return some gathered data to background then?

I'm trying to make an extension that can be invoked by externalMessage so it can be received in background only. That is why i'm trying to find out if result of puppeteer script can be passed with simple return, other than passing data via console.log or something :)

@gajananpp
Copy link
Owner

Hi @bestplay9384

You can directly execute puppeteer script in background using puppeteer-extension-transport package.

Checkout this example
https://github.com/gajananpp/puppeteer-extension-transport/tree/main/examples/extension-v3

@bestplay9384
Copy link
Author

bestplay9384 commented Aug 5, 2022

Hey @gajananpp,

I can't.

I've already made ability tu run puppeteer in extension with both ways - with remote debugging port and chrome.debugger api. Everything worked fine till moment i needed to run puppeteer scripts that are fetched from external source. I have that as string in extension. Then i discovered that eval is forbidden in manifest v3 everywhere but in sandbox. That's why im asking if it it possible with chrome.debugger api, with remote debugging port it is, already checked :)

Manifest v3 made it all so hard to achieve... I need sandbox to be able to use eval, sandbox has to be iframed, so i've placed it in popup (it can be popup or devtools panel as You did) and when "task" starts i'm opening popup in minimized window and only then communication is possible. But still background talks with popup, popup talks with sandbox via postMessage api, then sandbox when job is done tells about result to popup so it can send message via runtime to backend and it can finish externalMessage event. I hope google will not leave manifest in such awful situation till manifest v2 deprecation occur 👍

@gajananpp
Copy link
Owner

@bestplay9384, yes creating or migrating to v3 extension is really difficult if it involves working with eval. I thought about your use case but couldn't think of any direct way to send data back to background. I hope at least they would provide chrome.runtime.sendMessage api in sandbox page in future. For debugging purpose in this extension, i am storing all the CDP commands and their responses in an object in background page, maybe something like that could be done if only response has to be gathered.

https://github.com/gajananpp/puppeteer-ide-extension/blob/main/src/background.ts#L129-L133

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants