playwright-core
Advanced tools
Comparing version 0.11.1-next.1583179440445 to 0.11.1-next.1583187564534
@@ -21,3 +21,4 @@ /** | ||
browsers: ['webkit', 'chromium', 'firefox'], | ||
respectEnvironmentVariables: false, | ||
}); | ||
@@ -27,3 +27,3 @@ /** | ||
export { Request, Response } from './network'; | ||
export { FileChooser, Page, Worker } from './page'; | ||
export { FileChooser, Page, PageEvent, Worker } from './page'; | ||
export { Selectors } from './selectors'; | ||
@@ -34,3 +34,2 @@ export { CRBrowser as ChromiumBrowser } from './chromium/crBrowser'; | ||
export { CRSession as ChromiumSession } from './chromium/crConnection'; | ||
export { CRTarget as ChromiumTarget } from './chromium/crTarget'; | ||
export { FFBrowser as FirefoxBrowser } from './firefox/ffBrowser'; | ||
@@ -37,0 +36,0 @@ export { WKBrowser as WebKitBrowser } from './webkit/wkBrowser'; |
@@ -40,2 +40,3 @@ "use strict"; | ||
exports.Page = page_1.Page; | ||
exports.PageEvent = page_1.PageEvent; | ||
exports.Worker = page_1.Worker; | ||
@@ -52,4 +53,2 @@ var selectors_1 = require("./selectors"); | ||
exports.ChromiumSession = crConnection_1.CRSession; | ||
var crTarget_1 = require("./chromium/crTarget"); | ||
exports.ChromiumTarget = crTarget_1.CRTarget; | ||
var ffBrowser_1 = require("./firefox/ffBrowser"); | ||
@@ -56,0 +55,0 @@ exports.FirefoxBrowser = ffBrowser_1.FFBrowser; |
@@ -50,3 +50,3 @@ /** | ||
close(): Promise<void>; | ||
browserTarget(): CRTarget; | ||
createBrowserSession(): Promise<CRSession>; | ||
startTracing(page: Page | undefined, options?: { | ||
@@ -87,8 +87,5 @@ path?: string; | ||
close(): Promise<void>; | ||
pageTarget(page: Page): CRTarget; | ||
targets(): CRTarget[]; | ||
waitForTarget(predicate: (arg0: CRTarget) => boolean, options?: { | ||
timeout?: number; | ||
}): Promise<CRTarget>; | ||
backgroundPages(): Promise<Page[]>; | ||
createSession(page: Page): Promise<CRSession>; | ||
_browserClosed(): void; | ||
} |
@@ -24,2 +24,3 @@ "use strict"; | ||
const crConnection_1 = require("./crConnection"); | ||
const page_1 = require("../page"); | ||
const crTarget_1 = require("./crTarget"); | ||
@@ -78,4 +79,27 @@ const browser_1 = require("../browser"); | ||
this._targets.set(event.targetInfo.targetId, target); | ||
if (target._isInitialized || await target._initializedPromise) | ||
context.emit(events_1.Events.CRBrowserContext.TargetCreated, target); | ||
try { | ||
switch (targetInfo.type) { | ||
case 'page': { | ||
const page = await target.page(); | ||
const event = new page_1.PageEvent(page); | ||
context.emit(events_2.Events.BrowserContext.PageEvent, event); | ||
break; | ||
} | ||
case 'background_page': { | ||
const page = await target.page(); | ||
const event = new page_1.PageEvent(page); | ||
context.emit(events_1.Events.CRBrowserContext.BackgroundPage, event); | ||
break; | ||
} | ||
case 'service_worker': { | ||
const serviceWorker = await target.serviceWorker(); | ||
context.emit(events_1.Events.CRBrowserContext.ServiceWorker, serviceWorker); | ||
break; | ||
} | ||
} | ||
} | ||
catch (e) { | ||
// Do not dispatch the event if initialization failed. | ||
helper_1.debugError(e); | ||
} | ||
} | ||
@@ -87,4 +111,2 @@ async _targetDestroyed(event) { | ||
target._didClose(); | ||
if (await target._initializedPromise) | ||
target.context().emit(events_1.Events.CRBrowserContext.TargetDestroyed, target); | ||
} | ||
@@ -94,7 +116,3 @@ _targetInfoChanged(event) { | ||
helper_1.assert(target, 'target should exist before targetInfoChanged'); | ||
const previousURL = target.url(); | ||
const wasInitialized = target._isInitialized; | ||
target._targetInfoChanged(event.targetInfo); | ||
if (wasInitialized && previousURL !== target.url()) | ||
target.context().emit(events_1.Events.CRBrowserContext.TargetChanged, target); | ||
} | ||
@@ -113,4 +131,4 @@ async _closePage(page) { | ||
} | ||
browserTarget() { | ||
return [...this._targets.values()].find(t => t.type() === 'browser'); | ||
async createBrowserSession() { | ||
return await this._connection.createBrowserSession(); | ||
} | ||
@@ -270,31 +288,10 @@ async startTracing(page, options = {}) { | ||
} | ||
pageTarget(page) { | ||
return crTarget_1.CRTarget.fromPage(page); | ||
async backgroundPages() { | ||
const targets = this._browser._allTargets().filter(target => target.context() === this && target.type() === 'background_page'); | ||
const pages = await Promise.all(targets.map(target => target.page())); | ||
return pages.filter(page => !!page); | ||
} | ||
targets() { | ||
return this._browser._allTargets().filter(t => t.context() === this); | ||
async createSession(page) { | ||
return crTarget_1.CRTarget.fromPage(page).sessionFactory(); | ||
} | ||
async waitForTarget(predicate, options = {}) { | ||
const { timeout = 30000 } = options; | ||
const existingTarget = this._browser._allTargets().find(predicate); | ||
if (existingTarget) | ||
return existingTarget; | ||
let resolve; | ||
const targetPromise = new Promise(x => resolve = x); | ||
this.on(events_1.Events.CRBrowserContext.TargetCreated, check); | ||
this.on(events_1.Events.CRBrowserContext.TargetChanged, check); | ||
try { | ||
if (!timeout) | ||
return await targetPromise; | ||
return await helper_1.helper.waitWithTimeout(targetPromise, 'target', timeout); | ||
} | ||
finally { | ||
this.removeListener(events_1.Events.CRBrowserContext.TargetCreated, check); | ||
this.removeListener(events_1.Events.CRBrowserContext.TargetChanged, check); | ||
} | ||
function check(target) { | ||
if (predicate(target)) | ||
resolve(target); | ||
} | ||
} | ||
_browserClosed() { | ||
@@ -301,0 +298,0 @@ this._closed = true; |
@@ -116,5 +116,5 @@ "use strict"; | ||
} | ||
send(method, params) { | ||
async send(method, params) { | ||
if (!this._connection) | ||
return Promise.reject(new Error(`Protocol error (${method}): Session closed. Most likely the ${this._targetType} has been closed.`)); | ||
throw new Error(`Protocol error (${method}): Session closed. Most likely the ${this._targetType} has been closed.`); | ||
const id = this._connection._rawSend(this._sessionId, { method, params }); | ||
@@ -121,0 +121,0 @@ return new Promise((resolve, reject) => { |
@@ -67,19 +67,10 @@ "use strict"; | ||
} | ||
let callFunctionOnPromise; | ||
try { | ||
callFunctionOnPromise = this._client.send('Runtime.callFunctionOn', { | ||
functionDeclaration: functionText + '\n' + suffix + '\n', | ||
executionContextId: this._contextId, | ||
arguments: args.map(convertArgument.bind(this)), | ||
returnByValue, | ||
awaitPromise: true, | ||
userGesture: true | ||
}); | ||
} | ||
catch (err) { | ||
if (err instanceof TypeError && err.message.startsWith('Converting circular structure to JSON')) | ||
err.message += ' Are you passing a nested JSHandle?'; | ||
throw err; | ||
} | ||
const { exceptionDetails, result: remoteObject } = await callFunctionOnPromise.catch(rewriteError); | ||
const { exceptionDetails, result: remoteObject } = await this._client.send('Runtime.callFunctionOn', { | ||
functionDeclaration: functionText + '\n' + suffix + '\n', | ||
executionContextId: this._contextId, | ||
arguments: args.map(convertArgument.bind(this)), | ||
returnByValue, | ||
awaitPromise: true, | ||
userGesture: true | ||
}).catch(rewriteError); | ||
if (exceptionDetails) | ||
@@ -121,2 +112,4 @@ throw new Error('Evaluation failed: ' + crProtocolHelper_1.getExceptionMessage(exceptionDetails)); | ||
throw new Error('Execution context was destroyed, most likely because of a navigation.'); | ||
if (error instanceof TypeError && error.message.startsWith('Converting circular structure to JSON')) | ||
error.message += ' Are you passing a nested JSHandle?'; | ||
throw error; | ||
@@ -123,0 +116,0 @@ } |
@@ -27,3 +27,3 @@ /** | ||
readonly _targetId: string; | ||
private _sessionFactory; | ||
readonly sessionFactory: () => Promise<CRSession>; | ||
private _pagePromise; | ||
@@ -44,4 +44,3 @@ _crPage: CRPage | null; | ||
opener(): CRTarget | null; | ||
createCDPSession(): Promise<CRSession>; | ||
_targetInfoChanged(targetInfo: Protocol.Target.TargetInfo): void; | ||
} |
@@ -36,3 +36,3 @@ "use strict"; | ||
this._targetId = targetInfo.targetId; | ||
this._sessionFactory = sessionFactory; | ||
this.sessionFactory = sessionFactory; | ||
this._initializedPromise = new Promise(fulfill => this._initializedCallback = fulfill).then(async (success) => { | ||
@@ -64,3 +64,3 @@ if (!success) | ||
if ((this._targetInfo.type === 'page' || this._targetInfo.type === 'background_page') && !this._pagePromise) { | ||
this._pagePromise = this._sessionFactory().then(async (client) => { | ||
this._pagePromise = this.sessionFactory().then(async (client) => { | ||
this._crPage = new crPage_1.CRPage(client, this._browser, this._browserContext); | ||
@@ -81,3 +81,3 @@ const page = this._crPage.page(); | ||
// TODO(einbinder): Make workers send their console logs. | ||
this._workerPromise = this._sessionFactory().then(session => { | ||
this._workerPromise = this.sessionFactory().then(session => { | ||
const worker = new page_1.Worker(this._targetInfo.url); | ||
@@ -112,5 +112,2 @@ session.once('Runtime.executionContextCreated', async (event) => { | ||
} | ||
createCDPSession() { | ||
return this._sessionFactory(); | ||
} | ||
_targetInfoChanged(targetInfo) { | ||
@@ -117,0 +114,0 @@ this._targetInfo = targetInfo; |
@@ -19,6 +19,5 @@ /** | ||
CRBrowserContext: { | ||
TargetCreated: string; | ||
TargetDestroyed: string; | ||
TargetChanged: string; | ||
BackgroundPage: string; | ||
ServiceWorker: string; | ||
}; | ||
}; |
@@ -21,7 +21,6 @@ "use strict"; | ||
CRBrowserContext: { | ||
TargetCreated: 'targetcreated', | ||
TargetDestroyed: 'targetdestroyed', | ||
TargetChanged: 'targetchanged', | ||
BackgroundPage: 'backgroundpage', | ||
ServiceWorker: 'serviceworker', | ||
} | ||
}; | ||
//# sourceMappingURL=events.js.map |
@@ -23,2 +23,3 @@ /** | ||
Close: string; | ||
PageEvent: string; | ||
}; | ||
@@ -25,0 +26,0 @@ BrowserServer: { |
@@ -24,3 +24,4 @@ "use strict"; | ||
BrowserContext: { | ||
Close: 'close' | ||
Close: 'close', | ||
PageEvent: 'page', | ||
}, | ||
@@ -27,0 +28,0 @@ BrowserServer: { |
@@ -50,3 +50,3 @@ "use strict"; | ||
} | ||
send(method, params) { | ||
async send(method, params) { | ||
const id = this.nextMessageId(); | ||
@@ -142,5 +142,5 @@ this._rawSend({ id, method, params }); | ||
} | ||
send(method, params) { | ||
async send(method, params) { | ||
if (this._disposed) | ||
return Promise.reject(new Error(`Protocol error (${method}): Session closed. Most likely the ${this._targetType} has been closed.`)); | ||
throw new Error(`Protocol error (${method}): Session closed. Most likely the ${this._targetType} has been closed.`); | ||
const id = this._connection.nextMessageId(); | ||
@@ -147,0 +147,0 @@ this._rawSend({ method, params, id }); |
@@ -77,17 +77,8 @@ "use strict"; | ||
}); | ||
let callFunctionPromise; | ||
try { | ||
callFunctionPromise = this._session.send('Runtime.callFunction', { | ||
functionDeclaration: functionText, | ||
args: protocolArgs, | ||
returnByValue, | ||
executionContextId: this._executionContextId | ||
}); | ||
} | ||
catch (err) { | ||
if (err instanceof TypeError && err.message.startsWith('Converting circular structure to JSON')) | ||
err.message += ' Are you passing a nested JSHandle?'; | ||
throw err; | ||
} | ||
const payload = await callFunctionPromise.catch(rewriteError); | ||
const payload = await this._session.send('Runtime.callFunction', { | ||
functionDeclaration: functionText, | ||
args: protocolArgs, | ||
returnByValue, | ||
executionContextId: this._executionContextId | ||
}).catch(rewriteError); | ||
checkException(payload.exceptionDetails); | ||
@@ -102,2 +93,4 @@ if (returnByValue) | ||
throw new Error('Execution context was destroyed, most likely because of a navigation.'); | ||
if (error instanceof TypeError && error.message.startsWith('Converting circular structure to JSON')) | ||
error.message += ' Are you passing a nested JSHandle?'; | ||
throw error; | ||
@@ -104,0 +97,0 @@ } |
@@ -93,2 +93,7 @@ /** | ||
}; | ||
export declare class PageEvent { | ||
private readonly _page; | ||
constructor(page: Page); | ||
page(): Promise<Page>; | ||
} | ||
export declare class Page extends platform.EventEmitter { | ||
@@ -95,0 +100,0 @@ private _closed; |
@@ -31,2 +31,11 @@ "use strict"; | ||
const platform = require("./platform"); | ||
class PageEvent { | ||
constructor(page) { | ||
this._page = page; | ||
} | ||
async page( /* options?: frames.NavigateOptions */) { | ||
return this._page; | ||
} | ||
} | ||
exports.PageEvent = PageEvent; | ||
class Page extends platform.EventEmitter { | ||
@@ -33,0 +42,0 @@ constructor(delegate, browserContext) { |
@@ -42,11 +42,3 @@ /** | ||
export declare function makeWaitForNextTask(): (callback: () => void) => void; | ||
export declare class WebSocketTransport implements ConnectionTransport { | ||
private _ws; | ||
onmessage?: (message: string) => void; | ||
onclose?: () => void; | ||
private _connectPromise; | ||
constructor(url: string); | ||
send(message: string): Promise<void>; | ||
close(): void; | ||
} | ||
export declare function connectToWebsocket<T>(url: string, onopen: (transport: ConnectionTransport) => Promise<T>): Promise<T>; | ||
export {}; |
@@ -280,2 +280,12 @@ "use strict"; | ||
exports.makeWaitForNextTask = makeWaitForNextTask; | ||
// 'onmessage' handler must be installed synchronously when 'onopen' callback is invoked to | ||
// avoid missing incoming messages. | ||
async function connectToWebsocket(url, onopen) { | ||
const transport = new WebSocketTransport(url); | ||
return new Promise((fulfill, reject) => { | ||
transport._ws.addEventListener('open', async () => fulfill(await onopen(transport))); | ||
transport._ws.addEventListener('error', event => reject(new Error('WebSocket error: ' + event.message))); | ||
}); | ||
} | ||
exports.connectToWebsocket = connectToWebsocket; | ||
class WebSocketTransport { | ||
@@ -287,6 +297,2 @@ constructor(url) { | ||
}) : new WebSocket(url)); | ||
this._connectPromise = new Promise(fulfill => { | ||
this._ws.addEventListener('open', () => fulfill(null)); | ||
this._ws.addEventListener('error', event => fulfill(new Error('WebSocket error: ' + event.message))); | ||
}); | ||
// The 'ws' module in node sometimes sends us multiple messages in a single task. | ||
@@ -310,6 +316,3 @@ // In Web, all IO callbacks (e.g. WebSocket callbacks) | ||
} | ||
async send(message) { | ||
const error = await this._connectPromise; | ||
if (error) | ||
throw error; | ||
send(message) { | ||
this._ws.send(message); | ||
@@ -321,3 +324,2 @@ } | ||
} | ||
exports.WebSocketTransport = WebSocketTransport; | ||
const extensionToMime = { | ||
@@ -324,0 +326,0 @@ 'ai': 'application/postscript', |
@@ -27,4 +27,5 @@ /** | ||
private _downloadPath; | ||
private _downloadHost; | ||
readonly _revision: string; | ||
constructor(downloadPath: string, preferredRevision: string); | ||
constructor(downloadPath: string, downloadHost: (string | undefined), preferredRevision: string); | ||
name(): string; | ||
@@ -31,0 +32,0 @@ launch(options?: LaunchOptions & { |
@@ -35,4 +35,5 @@ "use strict"; | ||
class Chromium { | ||
constructor(downloadPath, preferredRevision) { | ||
constructor(downloadPath, downloadHost, preferredRevision) { | ||
this._downloadPath = downloadPath; | ||
this._downloadHost = downloadHost || 'https://storage.googleapis.com'; | ||
this._revision = preferredRevision; | ||
@@ -60,3 +61,4 @@ } | ||
const browser = await crBrowser_1.CRBrowser.connect(transport); | ||
await helper_1.helper.waitWithTimeout(browser._defaultContext.waitForTarget(t => t.type() === 'page'), 'first page', timeout); | ||
const firstPage = new Promise(r => browser._defaultContext.once(events_1.Events.BrowserContext.PageEvent, r)); | ||
await helper_1.helper.waitWithTimeout(firstPage, 'first page', timeout); | ||
// Hack: for typical launch scenario, ensure that close waits for actual process termination. | ||
@@ -105,3 +107,3 @@ const browserContext = browser._defaultContext; | ||
// our connection ignores kBrowserCloseMessageId. | ||
const t = transport || new platform.WebSocketTransport(browserWSEndpoint); | ||
const t = transport || await platform.connectToWebsocket(browserWSEndpoint, async (transport) => transport); | ||
const message = { method: 'Browser.close', id: crConnection_1.kBrowserCloseMessageId }; | ||
@@ -130,4 +132,5 @@ await t.send(JSON.stringify(message)); | ||
async connect(options) { | ||
const transport = new platform.WebSocketTransport(options.wsEndpoint); | ||
return crBrowser_1.CRBrowser.connect(transport, options.slowMo); | ||
return await platform.connectToWebsocket(options.wsEndpoint, transport => { | ||
return crBrowser_1.CRBrowser.connect(transport, options.slowMo); | ||
}); | ||
} | ||
@@ -184,3 +187,3 @@ executablePath() { | ||
path: path.join(this._downloadPath, '.local-chromium'), | ||
host: 'https://storage.googleapis.com', | ||
host: this._downloadHost, | ||
platform: (() => { | ||
@@ -187,0 +190,0 @@ const platform = os.platform(); |
@@ -17,14 +17,15 @@ /** | ||
*/ | ||
import { ConnectOptions } from '../browser'; | ||
import { BrowserContext } from '../browserContext'; | ||
import { TimeoutError } from '../errors'; | ||
import { FFBrowser } from '../firefox/ffBrowser'; | ||
import { BrowserFetcher, OnProgressCallback, BrowserFetcherOptions } from './browserFetcher'; | ||
import * as types from '../types'; | ||
import { TimeoutError } from '../errors'; | ||
import { LaunchOptions, BrowserType } from './browserType'; | ||
import { ConnectOptions } from '../browser'; | ||
import { BrowserFetcher, BrowserFetcherOptions, OnProgressCallback } from './browserFetcher'; | ||
import { BrowserServer } from './browserServer'; | ||
import { BrowserContext } from '../browserContext'; | ||
import { BrowserType, LaunchOptions } from './browserType'; | ||
export declare class Firefox implements BrowserType { | ||
private _downloadPath; | ||
private _downloadHost; | ||
readonly _revision: string; | ||
constructor(downloadPath: string, preferredRevision: string); | ||
constructor(downloadPath: string, downloadHost: (string | undefined), preferredRevision: string); | ||
downloadBrowserIfNeeded(onProgress?: OnProgressCallback): Promise<void>; | ||
@@ -31,0 +32,0 @@ name(): string; |
@@ -19,8 +19,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ffBrowser_1 = require("../firefox/ffBrowser"); | ||
const browserFetcher_1 = require("./browserFetcher"); | ||
const deviceDescriptors_1 = require("../deviceDescriptors"); | ||
const processLauncher_1 = require("./processLauncher"); | ||
const platform = require("../platform"); | ||
const ffConnection_1 = require("../firefox/ffConnection"); | ||
const fs = require("fs"); | ||
@@ -30,10 +24,17 @@ const os = require("os"); | ||
const util = require("util"); | ||
const deviceDescriptors_1 = require("../deviceDescriptors"); | ||
const errors_1 = require("../errors"); | ||
const events_1 = require("../events"); | ||
const ffBrowser_1 = require("../firefox/ffBrowser"); | ||
const ffConnection_1 = require("../firefox/ffConnection"); | ||
const helper_1 = require("../helper"); | ||
const platform = require("../platform"); | ||
const browserFetcher_1 = require("./browserFetcher"); | ||
const browserServer_1 = require("./browserServer"); | ||
const events_1 = require("../events"); | ||
const processLauncher_1 = require("./processLauncher"); | ||
const mkdtempAsync = platform.promisify(fs.mkdtemp); | ||
class Firefox { | ||
constructor(downloadPath, preferredRevision) { | ||
constructor(downloadPath, downloadHost, preferredRevision) { | ||
this._downloadPath = downloadPath; | ||
this._downloadHost = downloadHost || 'https://playwright.azureedge.net'; | ||
this._revision = preferredRevision; | ||
@@ -55,4 +56,6 @@ } | ||
throw new Error('userDataDir option is not supported in `browserType.launch`. Use `browserType.launchPersistent` instead'); | ||
const { browserServer, transport } = await this._launchServer(options, 'local'); | ||
const browser = await ffBrowser_1.FFBrowser.connect(transport, options && options.slowMo); | ||
const browserServer = await this._launchServer(options, 'local'); | ||
const browser = await platform.connectToWebsocket(browserServer.wsEndpoint(), transport => { | ||
return ffBrowser_1.FFBrowser.connect(transport, options && options.slowMo); | ||
}); | ||
// Hack: for typical launch scenario, ensure that close waits for actual process termination. | ||
@@ -64,8 +67,10 @@ browser.close = () => browserServer.close(); | ||
async launchServer(options) { | ||
return (await this._launchServer(options, 'server', undefined, options && options.port)).browserServer; | ||
return await this._launchServer(options, 'server', undefined, options && options.port); | ||
} | ||
async launchPersistent(userDataDir, options) { | ||
const { timeout = 30000 } = options || {}; | ||
const { browserServer, transport } = await this._launchServer(options, 'persistent', userDataDir); | ||
const browser = await ffBrowser_1.FFBrowser.connect(transport); | ||
const browserServer = await this._launchServer(options, 'persistent', userDataDir); | ||
const browser = await platform.connectToWebsocket(browserServer.wsEndpoint(), transport => { | ||
return ffBrowser_1.FFBrowser.connect(transport); | ||
}); | ||
await helper_1.helper.waitWithTimeout(browser._waitForTarget(t => t.type() === 'page'), 'first page', timeout); | ||
@@ -119,3 +124,3 @@ // Hack: for typical launch scenario, ensure that close waits for actual process termination. | ||
// our connection ignores kBrowserCloseMessageId. | ||
const transport = new platform.WebSocketTransport(browserWSEndpoint); | ||
const transport = await platform.connectToWebsocket(browserWSEndpoint, async (transport) => transport); | ||
const message = { method: 'Browser.close', params: {}, id: ffConnection_1.kBrowserCloseMessageId }; | ||
@@ -132,8 +137,9 @@ await transport.send(JSON.stringify(message)); | ||
const browserWSEndpoint = match[1]; | ||
browserServer = new browserServer_1.BrowserServer(launchedProcess, gracefullyClose, launchType === 'server' ? browserWSEndpoint : null); | ||
return { browserServer, transport: launchType === 'server' ? undefined : new platform.WebSocketTransport(browserWSEndpoint) }; | ||
browserServer = new browserServer_1.BrowserServer(launchedProcess, gracefullyClose, browserWSEndpoint); | ||
return browserServer; | ||
} | ||
async connect(options) { | ||
const transport = new platform.WebSocketTransport(options.wsEndpoint); | ||
return ffBrowser_1.FFBrowser.connect(transport, options.slowMo); | ||
return await platform.connectToWebsocket(options.wsEndpoint, transport => { | ||
return ffBrowser_1.FFBrowser.connect(transport, options.slowMo); | ||
}); | ||
} | ||
@@ -184,3 +190,3 @@ executablePath() { | ||
path: path.join(this._downloadPath, '.local-firefox'), | ||
host: 'https://playwright.azureedge.net', | ||
host: this._downloadHost, | ||
platform: (() => { | ||
@@ -187,0 +193,0 @@ const platform = os.platform(); |
@@ -22,2 +22,7 @@ /** | ||
import { Firefox } from './firefox'; | ||
declare type PlaywrightOptions = { | ||
downloadPath: string; | ||
browsers: Array<('firefox' | 'webkit' | 'chromium')>; | ||
respectEnvironmentVariables: boolean; | ||
}; | ||
export declare class Playwright { | ||
@@ -32,6 +37,4 @@ readonly selectors: api.Selectors; | ||
readonly webkit: (WebKit | undefined); | ||
constructor(options: { | ||
downloadPath: string; | ||
browsers: Array<('firefox' | 'webkit' | 'chromium')>; | ||
}); | ||
constructor(options: PlaywrightOptions); | ||
} | ||
export {}; |
@@ -33,14 +33,21 @@ "use strict"; | ||
this.selectors = api.Selectors._instance(); | ||
const { downloadPath, browsers, } = options; | ||
const { downloadPath, browsers, respectEnvironmentVariables, } = options; | ||
this.devices = deviceDescriptors_1.DeviceDescriptors; | ||
this.errors = { TimeoutError: errors_1.TimeoutError }; | ||
const downloadHost = respectEnvironmentVariables ? getFromENV('PLAYWRIGHT_DOWNLOAD_HOST') : undefined; | ||
if (browsers.includes('chromium')) | ||
this.chromium = new chromium_1.Chromium(downloadPath, packageJSON.playwright.chromium_revision); | ||
this.chromium = new chromium_1.Chromium(downloadPath, downloadHost, packageJSON.playwright.chromium_revision); | ||
if (browsers.includes('webkit')) | ||
this.webkit = new webkit_1.WebKit(downloadPath, packageJSON.playwright.webkit_revision); | ||
this.webkit = new webkit_1.WebKit(downloadPath, downloadHost, packageJSON.playwright.webkit_revision); | ||
if (browsers.includes('firefox')) | ||
this.firefox = new firefox_1.Firefox(downloadPath, packageJSON.playwright.firefox_revision); | ||
this.firefox = new firefox_1.Firefox(downloadPath, downloadHost, packageJSON.playwright.firefox_revision); | ||
} | ||
} | ||
exports.Playwright = Playwright; | ||
function getFromENV(name) { | ||
let value = process.env[name]; | ||
value = value || process.env[`npm_config_${name.toLowerCase()}`]; | ||
value = value || process.env[`npm_package_config_${name.toLowerCase()}`]; | ||
return value; | ||
} | ||
//# sourceMappingURL=playwright.js.map |
@@ -27,4 +27,5 @@ /** | ||
private _downloadPath; | ||
private _downloadHost; | ||
readonly _revision: string; | ||
constructor(downloadPath: string, preferredRevision: string); | ||
constructor(downloadPath: string, downloadHost: (string | undefined), preferredRevision: string); | ||
name(): string; | ||
@@ -31,0 +32,0 @@ downloadBrowserIfNeeded(onProgress?: OnProgressCallback): Promise<void>; |
@@ -38,4 +38,5 @@ "use strict"; | ||
class WebKit { | ||
constructor(downloadPath, preferredRevision) { | ||
constructor(downloadPath, downloadHost, preferredRevision) { | ||
this._downloadPath = downloadPath; | ||
this._downloadHost = downloadHost || 'https://playwright.azureedge.net'; | ||
this._revision = preferredRevision; | ||
@@ -129,4 +130,5 @@ } | ||
async connect(options) { | ||
const transport = new platform.WebSocketTransport(options.wsEndpoint); | ||
return wkBrowser_1.WKBrowser.connect(transport, options.slowMo); | ||
return await platform.connectToWebsocket(options.wsEndpoint, transport => { | ||
return wkBrowser_1.WKBrowser.connect(transport, options.slowMo); | ||
}); | ||
} | ||
@@ -169,3 +171,3 @@ executablePath() { | ||
path: path.join(this._downloadPath, '.local-webkit'), | ||
host: 'https://playwright.azureedge.net', | ||
host: this._downloadHost, | ||
platform: (() => { | ||
@@ -231,3 +233,3 @@ const platform = os.platform(); | ||
SequenceNumberMixer._lastSequenceNumber = 1; | ||
async function wrapTransportWithWebSocket(transport, port) { | ||
function wrapTransportWithWebSocket(transport, port) { | ||
const server = new ws.Server({ port }); | ||
@@ -234,0 +236,0 @@ const guid = uuidv4(); |
@@ -24,4 +24,5 @@ "use strict"; | ||
connect: async (url) => { | ||
const transport = new platform.WebSocketTransport(url); | ||
return crBrowser_1.CRBrowser.connect(transport); | ||
return await platform.connectToWebsocket(url, transport => { | ||
return crBrowser_1.CRBrowser.connect(transport); | ||
}); | ||
} | ||
@@ -31,4 +32,5 @@ }, | ||
connect: async (url) => { | ||
const transport = new platform.WebSocketTransport(url); | ||
return wkBrowser_1.WKBrowser.connect(transport); | ||
return await platform.connectToWebsocket(url, transport => { | ||
return wkBrowser_1.WKBrowser.connect(transport); | ||
}); | ||
} | ||
@@ -38,4 +40,5 @@ }, | ||
connect: async (url) => { | ||
const transport = new platform.WebSocketTransport(url); | ||
return ffBrowser_1.FFBrowser.connect(transport); | ||
return await platform.connectToWebsocket(url, transport => { | ||
return ffBrowser_1.FFBrowser.connect(transport); | ||
}); | ||
} | ||
@@ -42,0 +45,0 @@ } |
{ | ||
"name": "playwright-core", | ||
"version": "0.11.1-next.1583179440445", | ||
"version": "0.11.1-next.1583187564534", | ||
"description": "A high-level API to automate web browsers", | ||
@@ -5,0 +5,0 @@ "repository": "github:Microsoft/playwright", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2421371
56985
14