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

docs: example of puppeteer in extension #12285

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ packages/ng-schematics/src/**/files/

# examples
examples/puppeteer-in-browser/out/**/*
examples/puppeteer-in-browser/node_modules/**/*
examples/puppeteer-in-browser/node_modules/**/*
examples/puppeteer-in-extension/out/**/*
examples/puppeteer-in-extension/node_modules/**/*
2 changes: 2 additions & 0 deletions examples/puppeteer-in-extension/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
out
node_modules
20 changes: 20 additions & 0 deletions examples/puppeteer-in-extension/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2024 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import {
connect,
ExtensionTransport,
} from 'puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js';

globalThis.testConnect = async url => {
const tab = await chrome.tabs.create({
url,
});
const browser = await connect({
transport: await ExtensionTransport.connectTab(tab.id),
});
const [page] = await browser.pages();
return await page.evaluate('document.title');
};
10 changes: 10 additions & 0 deletions examples/puppeteer-in-extension/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "Puppeteer in extension",
"version": "1.0",
"manifest_version": 3,
"background": {
"service_worker": "background.js",
"type": "module"
},
"permissions": ["debugger", "background"]
}
Loading
Loading