puppeteer-in-electron
Advanced tools
Comparing version 2.0.4 to 3.0.0
@@ -20,3 +20,3 @@ <!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
- `app` **App** The app imported from electron. | ||
- `port` **[number][7]** Port to host the DevTools websocket connection. (optional, default `14292`) | ||
- `port` **[number][7]** Port to host the DevTools websocket connection. (optional, default `0`) | ||
@@ -23,0 +23,0 @@ ## connect |
@@ -7,2 +7,3 @@ "use strict"; | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const get_port_1 = __importDefault(require("get-port")); | ||
const async_retry_1 = __importDefault(require("async-retry")); | ||
@@ -16,3 +17,3 @@ const uuid_1 = __importDefault(require("uuid")); | ||
*/ | ||
exports.initialize = async (app, port = 14292) => { | ||
exports.initialize = async (app, port = 0) => { | ||
if (!app) { | ||
@@ -25,3 +26,3 @@ throw new Error("The parameter 'app' was not passed in. " + | ||
} | ||
if (port <= 0 || port > 65535) { | ||
if (port < 0 || port > 65535) { | ||
throw new Error(`Invalid port ${port}.`); | ||
@@ -32,3 +33,5 @@ } | ||
} | ||
app.commandLine.appendSwitch("remote-debugging-port", `${port}`); | ||
const actualPort = port === 0 ? await get_port_1.default() : port; | ||
app.commandLine.appendSwitch("remote-debugging-port", `${actualPort}`); | ||
app.commandLine.appendSwitch("remote-debugging-address", "127.0.0.1"); | ||
const electronMajor = parseInt(app.getVersion().split(".")[0], 10); | ||
@@ -35,0 +38,0 @@ // NetworkService crashes in electron 6. |
@@ -11,3 +11,3 @@ "use strict"; | ||
const main = async () => { | ||
index_1.default.initialize(electron_1.app); | ||
await index_1.default.initialize(electron_1.app); | ||
const browser = await index_1.default.connect(electron_1.app, puppeteer_core_1.default); | ||
@@ -14,0 +14,0 @@ const window = new electron_1.BrowserWindow(); |
12
index.ts
import fetch from "node-fetch"; | ||
import getPort from "get-port"; | ||
import retry from "async-retry"; | ||
@@ -16,3 +17,3 @@ import uuid from "uuid"; | ||
*/ | ||
export const initialize = async (app: App, port: number = 14292) => { | ||
export const initialize = async (app: App, port: number = 0) => { | ||
if (!app) { | ||
@@ -27,3 +28,3 @@ throw new Error("The parameter 'app' was not passed in. " + | ||
if (port <= 0 || port > 65535) { | ||
if (port < 0 || port > 65535) { | ||
throw new Error(`Invalid port ${port}.`); | ||
@@ -36,6 +37,11 @@ } | ||
const actualPort = port === 0 ? await getPort() : port; | ||
app.commandLine.appendSwitch( | ||
"remote-debugging-port", | ||
`${port}` | ||
`${actualPort}` | ||
); | ||
app.commandLine.appendSwitch( | ||
"remote-debugging-address", | ||
"127.0.0.1" | ||
); | ||
const electronMajor = parseInt( | ||
@@ -42,0 +48,0 @@ app.getVersion().split(".")[0], |
{ | ||
"name": "puppeteer-in-electron", | ||
"version": "2.0.4", | ||
"version": "3.0.0", | ||
"description": "Run puppeteer within an electron app.", | ||
@@ -31,2 +31,3 @@ "main": "./bin/index.js", | ||
"async-retry": "^1.3.1", | ||
"get-port": "^5.1.1", | ||
"node-fetch": "^2.6.0", | ||
@@ -33,0 +34,0 @@ "uuid": "^3.3.3" |
# Introducing puppeteer-in-electron | ||
Run puppeteer within an electron app. | ||
Use puppeteer to test and control your electron application. | ||
``` | ||
@@ -16,3 +16,3 @@ npm install puppeteer-in-electron puppeteer-core electron | ||
const main = async () => { | ||
pie.initialize(app); | ||
await pie.initialize(app); | ||
const browser = await pie.connect(app, puppeteer); | ||
@@ -39,3 +39,3 @@ | ||
const main = async () => { | ||
pie.initialize(app); | ||
await pie.initialize(app); | ||
const browser = await pie.connect(app, puppeteer); | ||
@@ -42,0 +42,0 @@ |
@@ -8,3 +8,3 @@ /* eslint-disable @typescript-eslint/no-var-requires */ | ||
const main = async () => { | ||
pie.initialize(app); | ||
await pie.initialize(app); | ||
const browser = await pie.connect( | ||
@@ -11,0 +11,0 @@ app, |
@@ -7,3 +7,3 @@ import {BrowserWindow, app} from "electron"; | ||
const main = async () => { | ||
pie.initialize(app); | ||
await pie.initialize(app); | ||
const browser = await pie.connect( | ||
@@ -10,0 +10,0 @@ app, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26179
391
8
+ Addedget-port@^5.1.1
+ Addedget-port@5.1.1(transitive)