mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: remove puppeteer-web (#5750)
We don't support it and v3 shipped without including puppeteer-web in the browser. People are welcome to manually use Browserify to try to get Puppeteer running in a browser but it ultimately isn't our primary focus right now. Getting puppeteer-core able to run in a browser is something we'll be looking at in the future so we'll revisit this soon.
This commit is contained in:
parent
1358b45fca
commit
3ed2f6b0ac
2
index.js
2
index.js
@ -18,7 +18,6 @@ const {helper} = require('./lib/helper');
|
||||
const api = require('./lib/api');
|
||||
const {Page} = require('./lib/Page');
|
||||
for (const className in api) {
|
||||
// Puppeteer-web excludes certain classes from bundle, e.g. BrowserFetcher.
|
||||
if (typeof api[className] === 'function')
|
||||
helper.installAsyncStackHooks(api[className]);
|
||||
}
|
||||
@ -26,7 +25,6 @@ for (const className in api) {
|
||||
// Expose alias for deprecated method.
|
||||
Page.prototype.emulateMedia = Page.prototype.emulateMediaType;
|
||||
|
||||
// If node does not support async await, use the compiled version.
|
||||
const Puppeteer = require('./lib/Puppeteer');
|
||||
const packageJson = require('./package.json');
|
||||
let preferredRevision = packageJson.puppeteer.chromium_revision;
|
||||
|
@ -1,6 +0,0 @@
|
||||
const base = require('./base');
|
||||
|
||||
module.exports = {
|
||||
...base,
|
||||
spec: 'utils/browser/*.spec.js',
|
||||
};
|
@ -27,9 +27,7 @@
|
||||
"doc": "node utils/doclint/cli.js",
|
||||
"tsc": "tsc --version && tsc -p . && cp src/protocol.d.ts lib/ && cp src/externs.d.ts lib/",
|
||||
"apply-next-version": "node utils/apply_next_version.js",
|
||||
"bundle": "npm run tsc && npx browserify -r ./index.js:puppeteer -o utils/browser/puppeteer-web.js",
|
||||
"test-types": "node utils/doclint/generate_types && tsc --version && tsc -p utils/doclint/generate_types/test/",
|
||||
"unit-bundle": "mocha --config mocha-config/browser-bundle-tests.js",
|
||||
"update-protocol-d-ts": "node utils/protocol-types-generator",
|
||||
"test-install": "scripts/test-install.sh"
|
||||
},
|
||||
|
@ -3,6 +3,4 @@
|
||||
npm run lint &&
|
||||
npm run coverage &&
|
||||
npm run test-doclint &&
|
||||
npm run test-types &&
|
||||
npm run bundle &&
|
||||
npm run unit-bundle
|
||||
npm run test-types
|
||||
|
@ -1,37 +0,0 @@
|
||||
# Bundling For Web Browsers
|
||||
|
||||
To bundle Puppeteer using [Browserify](http://browserify.org/):
|
||||
|
||||
1. Clone Puppeteer repository: `git clone https://github.com/puppeteer/puppeteer && cd puppeteer`
|
||||
2. `npm install`
|
||||
3. Run `npm run bundle`
|
||||
|
||||
This will create `./utils/browser/puppeteer-web.js` file that contains Puppeteer bundle.
|
||||
|
||||
You can use it later on in your web page to drive
|
||||
another browser instance through its WS Endpoint:
|
||||
|
||||
```html
|
||||
<script src='./puppeteer-web.js'></script>
|
||||
<script>
|
||||
const puppeteer = require('puppeteer');
|
||||
const browser = await puppeteer.connect({
|
||||
browserWSEndpoint: '<another-browser-ws-endpont>'
|
||||
});
|
||||
// ... drive automation ...
|
||||
</script>
|
||||
```
|
||||
|
||||
See our [puppeteer-web tests](https://github.com/puppeteer/puppeteer/blob/master/utils/browser/test.js)
|
||||
for details.
|
||||
|
||||
### Running inside Chrome Extension
|
||||
|
||||
You might want to enable `unsafe-eval` inside the extension by adding the following
|
||||
to your `manifest.json` file:
|
||||
|
||||
```
|
||||
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
|
||||
```
|
||||
|
||||
Please see discussion in https://github.com/puppeteer/puppeteer/issues/3455.
|
@ -1 +0,0 @@
|
||||
module.exports = window.WebSocket;
|
@ -1,90 +0,0 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const puppeteer = require('../..');
|
||||
const {TestServer} = require('../testserver/');
|
||||
const expect = require('expect');
|
||||
|
||||
const puppeteerWebPath = path.join(__dirname, 'puppeteer-web.js');
|
||||
if (!fs.existsSync(puppeteerWebPath))
|
||||
throw new Error(`puppeteer-web is not built; run "npm run bundle"`);
|
||||
const puppeteerWeb = fs.readFileSync(puppeteerWebPath, 'utf8');
|
||||
|
||||
const state = {};
|
||||
|
||||
before(async() => {
|
||||
const assetsPath = path.join(__dirname, '..', '..', 'test', 'assets');
|
||||
const port = 8998;
|
||||
state.server = await TestServer.create(assetsPath, port);
|
||||
state.serverConfig = {
|
||||
PREFIX: `http://localhost:${port}`,
|
||||
EMPTY_PAGE: `http://localhost:${port}/empty.html`,
|
||||
};
|
||||
state.browser = await puppeteer.launch();
|
||||
});
|
||||
|
||||
after(async() => {
|
||||
await Promise.all([
|
||||
state.server.stop(),
|
||||
state.browser.close()
|
||||
]);
|
||||
state.browser = null;
|
||||
state.server = null;
|
||||
});
|
||||
|
||||
beforeEach(async() => {
|
||||
state.page = await state.browser.newPage();
|
||||
await state.page.evaluateOnNewDocument(puppeteerWeb);
|
||||
await state.page.addScriptTag({
|
||||
content: puppeteerWeb + '\n//# sourceURL=puppeteer-web.js'
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async() => {
|
||||
await state.page.close();
|
||||
state.page = null;
|
||||
});
|
||||
|
||||
describe('Puppeteer-Web', () => {
|
||||
it('should work over web socket', async() => {
|
||||
const {page, serverConfig} = state;
|
||||
const browser2 = await puppeteer.launch();
|
||||
// Use in-page puppeteer to create a new page and navigate it to the EMPTY_PAGE
|
||||
await page.evaluate(async(browserWSEndpoint, serverConfig) => {
|
||||
const puppeteer = require('puppeteer');
|
||||
const browser = await puppeteer.connect({browserWSEndpoint});
|
||||
const page = await browser.newPage();
|
||||
await page.goto(serverConfig.EMPTY_PAGE);
|
||||
}, browser2.wsEndpoint(), serverConfig);
|
||||
const pageURLs = (await browser2.pages()).map(page => page.url()).sort();
|
||||
expect(pageURLs).toEqual([
|
||||
'about:blank',
|
||||
serverConfig.EMPTY_PAGE
|
||||
]);
|
||||
await browser2.close();
|
||||
});
|
||||
it('should work over exposed DevTools protocol', async() => {
|
||||
const {browser, page, serverConfig} = state;
|
||||
// Expose devtools protocol binding into page.
|
||||
const session = await browser.target().createCDPSession();
|
||||
const pageInfo = (await session.send('Target.getTargets')).targetInfos.find(info => info.attached);
|
||||
await session.send('Target.exposeDevToolsProtocol', {targetId: pageInfo.targetId});
|
||||
await session.detach();
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
|
||||
// Use in-page puppeteer to create a new page and navigate it to the EMPTY_PAGE
|
||||
await page.evaluate(async serverConfig => {
|
||||
const puppeteer = require('puppeteer');
|
||||
window.cdp.close = () => {};
|
||||
const browser = await puppeteer.connect({transport: window.cdp});
|
||||
const page = await browser.newPage();
|
||||
await page.goto(serverConfig.EMPTY_PAGE);
|
||||
}, serverConfig);
|
||||
const pageURLs = (await browser.pages()).map(page => page.url()).sort();
|
||||
expect(pageURLs).toEqual([
|
||||
'about:blank',
|
||||
'about:blank',
|
||||
serverConfig.EMPTY_PAGE
|
||||
]);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user