-
Notifications
You must be signed in to change notification settings - Fork 9k
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
Is it possible to run puppeteer on electron window? #4655
Comments
If you want to run puppeteer on an already running chromium environment, there's a workaround somewhere that requires you to download a separate chromium instance and include it in the window... which i don't recommend cuz it's heavy af... I'm currently running electron with reactjs on the frontend, calling endpoints on nodejs that runs puppeteer... i used the create-react-app to setup like 95% of the stuff automatically |
Meanwhile I was digging a bit and actually found a way to attach puppeteer to electron instance however, it doesn't seem like this solution is still working, due to the electron not supporting the DevTools protocols which is mentioned in several issues like electron/electron#17776, #3793 and acknowledged in #4283 |
I've found a way around this and feel really silly that I did not see if before. In your JavaScript file to boot electron up, you use puppeteer inside there. |
@AnthoniG If you have the time, would you be able to include a code snippet? I am having trouble with this same task right now |
@WilliamChiu Here is the link. It's not fully fleshed out as it's all I had time for. However the basics are there. It uses Typescript and I use Yarn rather than npm (hence yarn.lock) Let me know if you have any problems or questions :) |
Thank you! This was very helpful |
I wrote a small library to take care of this for my own projects: It uses the above webSocketDebuggerUrl approach. This does work in the latest version of puppeteer and electron. Disclaimer, the whole library needs a lot of testing. The other thing I spent a long time trying to solve was how to associate an electron BrowserWindow with a puppeteer Page. I ended up writing a routine that injects JavaScript into the BrowserWindow and searches for that specific Page in puppeteer. I would note that there are a few limitations in puppeteer, for example you cannot intercept requests due to electron not supporting the network service. |
Hello, im trying to make puppeteer run with the instance of chromium from electron, my code is based from @AnthoniG but i keep getting errors, could you guys help me? |
|
@TrevorSundberg Would you mind adding a code snippet showing how you were able to render a Puppeteer |
@JustinELRoberts I'm not sure I understand what you mean by render? Basically once you connect puppeteer to electron, puppeteer can control all the pages (including browser windows). The only problem is that puppeteer identifies everything using target-ids, whereas the BrowserWindow does not expose these target-ids so I had to come up with a way to associate these two together. I did this by looping over all the pages in puppeteer, and setting some Javascript on the BrowserWindow so that I could find the right one: Does this answer your question? If not feel free to elaborate and I'll try and help |
@TrevorSundberg Sorry I'm finding it difficult to word exactly what I'm trying to do. From my understanding, your library allows us to use Puppeteer to control Electron I specifically @'ed you because I thought that's what you were saying you did in the second to last paragraph of your this message. |
I see, I'm not sure that I know how to achieve that. Provided my understanding of everything is correct*, electron is running it's own compiled version of Chromium, which means you can't just have puppeteer run a full blown instance of real Chromium and have it somehow link into electron; different processes, different binaries, etc. I haven't used electron extensively, but there might be a way to expose The thing I was talking about in that paragraph, and in general with what I wrote, was that since electron was still a build of Chromium, it still happens to include the Chrome Devtools Protocol (a websocket protocol to control Chrome). Puppeteer was built around this, so through some hacky process I was able to expose the protocol in electron apps and connect puppeteer to it. This does not however create a real Chromium instance at all, it merely just controls electron with limitations, since again it's a fork of Chromium with things removed, such as your finding with |
The only other idea I can think of is that you do some sort of remoting where you run a full non-headless version of chromium but you either hide it and broadcast the screen, or do something very hacky where you place or parent the window to the electron window. |
Sorry to keep bothering you but could you please elaborate a bit more on how I could hack this together? My current solution is already running a non-headless version of Chromium through puppeteer so that bit isn't much of an issue. I just wanted to make these Chromium instances child windows of my |
About intercepting requests. Any workarounds on how we can deal with it? The problem is when you try to respond on intercepted request puppeteer thinks that request finished but in chrome dev tools I can see that something strange happened with the request: status finished and I can see the response but I can't set up headers and status to 200. And also response not appeared in javascript code. await chartPage.on('request', (req) => {
if (req.url().includes('TracsProxy')) {
console.log(req);
req.respond({
status: 200,
contentType: 'application/json',
body: JSON.stringify(tracsProxyMock),
});
} else {
req.continue();
}
}); |
@blohamen It's marked as closed so I'll have to investigate, not sure if there's another good workaround but let me know if you find one. |
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. |
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! |
Has anyone tried this and it worked? |
@hayzedDev What's not working for you? |
In nightmare.js, there is a possibility to take advantage of the electron window. That doesn't require us to use external chromium nor google chrome executables, because chromium is already bundled into electron.
So, can I take an advantage of that? Been slightly looking through docs and found out that
puppeteer
always requires to specify the chromium executable path to be used and there seem to be no way to overcome this and work nicely within electron process.Regards
The text was updated successfully, but these errors were encountered: