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
Feature Request: Support puppeteer-web (inside browser or chrome extension) #6058
Comments
We are working on this at the moment and you can follow progress in #6125. Fair warning, it's not something that will be finished anytime soon but it is on our radar. |
If speaking about browser extensions then there is |
@ilyaigpetrov why don't you try to inject script to the page? |
@webee I don't get it: what script? If you mean content-script then, please, check my original message:
|
@ilyaigpetrov I mean that you can inject js to the page from your content script. you can also communicate with the page. in your content script // inject js to the page, triggered by message
// 1. inject from src
// 2. inject plain js code
chrome.runtime.onMessage.addListener((msg, sender, reply) => {
if (msg.cmd === 'inject_src') {
let s = document.createElement('script');
s.src = msg.src;
s.onload = function () {
this.remove();
};
(document.head || document.body || document.documentElement).appendChild(s);
} else if (msg.cmd === 'inject_code') {
let s = document.createElement('script');
s.textContent = msg.code;
(document.head || document.body || document.documentElement).appendChild(s);
s.remove();
}
});
// communicate with page script.
// method#1, use window message
window.addEventListener('message', msg => {
// console.log('Content Script Received: ', msg);
// we only accept messages from ourselves
if (msg.source !== window) {
return;
}
let data = msg.data;
// only handle messages from page.
if (data.from === 'page') {
console.log('Content Script Received Data: ', data);
}
});
// method#2, use a Custom Event.
document.addEventListener('ContentScriptEvent', e => {
let detail = e.detail;
console.log('ContentScriptEvent: ', e, detail);
}); then in the injected javascript function dispatchContentScriptEvent(detail) {
document.dispatchEvent(new CustomEvent('ContentScriptEvent', { detail }));
}
dispatchContentScriptEvent({ msg: 'hello' });
window.addEventListener('message', msg => {
// we only accept messages from ourselves
if (msg.source !== window) {
return;
}
let data = msg.data;
// only handle messages from content script.
if (data.from === 'cs') {
console.log('Page Received Data: ', data);
}
});
window.postMessage({ from: 'page', msg: 'hello from the page' }); |
@ilyaigpetrov If you are still interested, i have created a puppeteer transport package with which you can use puppeteer in your extension's background page/service worker. Here is the repo. It uses chrome.debugger api. You can do const elementHandle = await page.waitForSelector('element_selector')
await elementHandle.hover() |
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! |
It seems puppeteer-web was removed in #5750.
Could you, please, provide puppeteer-web via npm as it is unofficially done by @entrptaher at https://www.npmjs.com/package/puppeteer-web with sources at https://github.com/entrptaher/puppeteer-web.
Motivation
I want to scrape some data from a web site. This data appears on the site on
onmouseover
event. I tried using a chrome extension but it seems because web site page and content-script are executed in different environments you can't dispatch amouseover
event from content-script which will triggermouseover
listener in the page. That's why I try to make my extension to use puppeteer.Here is the code that doesn't trigger
mouseover
event from extension:I don't want to write extension which communicates with external puppeteer run on NodeJS because of the following reasons:
The text was updated successfully, but these errors were encountered: