Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

playwright-core

Package Overview
Dependencies
Maintainers
1
Versions
4726
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

playwright-core - npm Package Compare versions

Comparing version 0.11.1-next.1583449329858 to 0.11.1-next.1583451168969

31

lib/chromium/crBrowser.js

@@ -40,3 +40,3 @@ "use strict";

this._connection = connection;
this._client = connection.rootSession;
this._client = this._connection.rootSession;
this._defaultContext = new CRBrowserContext(this, null, browserContext_1.validateBrowserContextOptions({}));

@@ -107,10 +107,14 @@ this._connection.on(crConnection_1.ConnectionEvents.Disconnected, () => {

case 'page': {
const page = await target.page();
const event = new page_1.PageEvent(page);
const event = new page_1.PageEvent(target.pageOrError());
context.emit(events_2.Events.BrowserContext.Page, event);
const opener = target.opener();
if (!opener)
break;
const openerPage = await opener.pageOrError();
if (openerPage instanceof page_1.Page && !openerPage.isClosed())
openerPage.emit(events_2.Events.Page.Popup, new page_1.PageEvent(target.pageOrError()));
break;
}
case 'background_page': {
const page = await target.page();
const event = new page_1.PageEvent(page);
const event = new page_1.PageEvent(target.pageOrError());
context.emit(events_1.Events.CRBrowserContext.BackgroundPage, event);

@@ -229,4 +233,4 @@ break;

const targets = this._browser._allTargets().filter(target => target.context() === this && target.type() === 'page');
const pages = await Promise.all(targets.map(target => target.page()));
return pages.filter(page => !!page);
const pages = await Promise.all(targets.map(target => target.pageOrError()));
return pages.filter(page => (page instanceof page_1.Page) && !page.isClosed());
}

@@ -237,4 +241,9 @@ async newPage() {

const target = this._browser._targets.get(targetId);
const page = await target.page();
return page;
const result = await target.pageOrError();
if (result instanceof page_1.Page) {
if (result.isClosed())
throw new Error('Page has been closed.');
return result;
}
throw result;
}

@@ -332,4 +341,4 @@ async cookies(...urls) {

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);
const pages = await Promise.all(targets.map(target => target.pageOrError()));
return pages.filter(page => (page instanceof page_1.Page) && !page.isClosed());
}

@@ -336,0 +345,0 @@ async createSession(page) {

@@ -334,3 +334,6 @@ "use strict";

return null;
return await openerTarget.page();
const openerPage = await openerTarget.pageOrError();
if (openerPage instanceof page_1.Page && !openerPage.isClosed())
return openerPage;
return null;
}

@@ -337,0 +340,0 @@ async reload() {

@@ -28,4 +28,3 @@ /**

readonly sessionFactory: () => Promise<CRSession>;
private _pagePromiseFulfill;
private _pagePromiseReject;
private _pagePromiseCallback;
private _pagePromise;

@@ -38,4 +37,4 @@ _crPage: CRPage | null;

_didClose(): void;
page(): Promise<Page | null>;
initializePageSession(session: CRSession): Promise<void>;
pageOrError(): Promise<Page | Error>;
serviceWorker(): Promise<Worker | null>;

@@ -42,0 +41,0 @@ url(): string;

@@ -20,3 +20,2 @@ "use strict";

const crConnection_1 = require("./crConnection");
const events_1 = require("../events");
const page_1 = require("../page");

@@ -29,4 +28,3 @@ const helper_1 = require("../helper");

constructor(browser, targetInfo, browserContext, sessionFactory) {
this._pagePromiseFulfill = null;
this._pagePromiseReject = null;
this._pagePromiseCallback = null;
this._pagePromise = null;

@@ -40,8 +38,4 @@ this._crPage = null;

this.sessionFactory = sessionFactory;
if (CRTarget.isPageType(targetInfo.type)) {
this._pagePromise = new Promise((fulfill, reject) => {
this._pagePromiseFulfill = fulfill;
this._pagePromiseReject = reject;
});
}
if (CRTarget.isPageType(targetInfo.type))
this._pagePromise = new Promise(f => this._pagePromiseCallback = f);
}

@@ -58,5 +52,2 @@ static fromPage(page) {

}
async page() {
return this._pagePromise;
}
async initializePageSession(session) {

@@ -69,17 +60,13 @@ this._crPage = new crPage_1.CRPage(session, this._browser, this._browserContext);

await this._crPage.initialize();
this._pagePromiseFulfill(page);
this._pagePromiseCallback(page);
}
catch (error) {
this._pagePromiseReject(error);
catch (e) {
this._pagePromiseCallback(e);
}
if (this.type() !== 'page')
return;
const opener = this.opener();
if (!opener)
return;
const openerPage = await opener.page();
if (!openerPage)
return;
openerPage.emit(events_1.Events.Page.Popup, page);
}
async pageOrError() {
if (this._targetInfo.type !== 'page' && this._targetInfo.type !== 'background_page')
throw new Error('Not a page.');
return this._pagePromise;
}
async serviceWorker() {

@@ -86,0 +73,0 @@ if (this._targetInfo.type !== 'service_worker')

@@ -52,3 +52,3 @@ /**

declare class Target {
_pagePromise?: Promise<Page>;
_pagePromise?: Promise<Page | Error>;
_ffPage: FFPage | null;

@@ -68,3 +68,3 @@ private readonly _browser;

context(): FFBrowserContext;
page(): Promise<Page>;
pageOrError(): Promise<Page | Error>;
_initPagePromise(session: FFSession): void;

@@ -71,0 +71,0 @@ browser(): FFBrowser;

@@ -147,12 +147,10 @@ "use strict";

target._initPagePromise(this._connection.getSession(payload.sessionId));
const page = await target.page();
if (!page)
const pageEvent = new page_1.PageEvent(target.pageOrError());
target.context().emit(events_1.Events.BrowserContext.Page, pageEvent);
const opener = target.opener();
if (!opener)
return;
target.context().emit(events_1.Events.BrowserContext.Page, new page_1.PageEvent(page));
const opener = target.opener();
if (opener && opener._pagePromise) {
const openerPage = await opener._pagePromise;
if (openerPage.listenerCount(events_1.Events.Page.Popup))
openerPage.emit(events_1.Events.Page.Popup, page);
}
const openerPage = await opener.pageOrError();
if (openerPage instanceof page_1.Page && !openerPage.isClosed())
openerPage.emit(events_1.Events.Page.Popup, pageEvent);
}

@@ -198,3 +196,3 @@ async close() {

}
async page() {
async pageOrError() {
if (this._type !== 'page')

@@ -212,8 +210,18 @@ throw new Error(`Cannot create page for "${this._type}" target`);

return null;
return await openerTarget.page();
const result = await openerTarget.pageOrError();
if (result instanceof page_1.Page && !result.isClosed())
return result;
return null;
});
const page = this._ffPage._page;
session.once(ffConnection_1.FFSessionEvents.Disconnected, () => page._didDisconnect());
await this._ffPage._initialize().catch(helper_1.debugError);
f(page);
let pageOrError;
try {
await this._ffPage._initialize();
pageOrError = page;
}
catch (e) {
pageOrError = e;
}
f(pageOrError);
});

@@ -262,4 +270,4 @@ }

const targets = this._browser._allTargets().filter(target => target.context() === this && target.type() === 'page');
const pages = await Promise.all(targets.map(target => target.page()));
return pages.filter(page => !!page);
const pages = await Promise.all(targets.map(target => target.pageOrError()));
return pages.filter(page => page instanceof page_1.Page && !page.isClosed());
}

@@ -272,3 +280,9 @@ async newPage() {

const target = this._browser._targets.get(targetId);
return target.page();
const result = await target.pageOrError();
if (result instanceof page_1.Page) {
if (result.isClosed())
throw new Error('Page has been closed.');
return result;
}
throw result;
}

@@ -275,0 +289,0 @@ async cookies(...urls) {

@@ -89,4 +89,4 @@ /**

export declare class PageEvent {
private readonly _page;
constructor(page: Page);
private readonly _pageOrError;
constructor(pageOrErrorPromise: Promise<Page | Error>);
page(): Promise<Page>;

@@ -93,0 +93,0 @@ }

@@ -32,7 +32,13 @@ "use strict";

class PageEvent {
constructor(page) {
this._page = page;
constructor(pageOrErrorPromise) {
this._pageOrError = pageOrErrorPromise;
}
async page( /* options?: frames.NavigateOptions */) {
return this._page;
const result = await this._pageOrError;
if (result instanceof Page) {
if (result.isClosed())
throw new Error('Page has been closed.');
return result;
}
throw result;
}

@@ -39,0 +45,0 @@ }

@@ -60,6 +60,10 @@ "use strict";

const browser = await crBrowser_1.CRBrowser.connect(transport, true);
const firstPage = new Promise(r => browser._defaultContext.once(events_1.Events.BrowserContext.Page, r));
const browserContext = browser._defaultContext;
function targets() {
return browser._allTargets().filter(target => target.context() === browserContext && target.type() === 'page');
}
const firstTarget = targets().length ? Promise.resolve() : new Promise(f => browserContext.once('page', f));
const firstPage = firstTarget.then(() => targets()[0].pageOrError());
await helper_1.helper.waitWithTimeout(firstPage, 'first page', timeout);
// Hack: for typical launch scenario, ensure that close waits for actual process termination.
const browserContext = browser._defaultContext;
browserContext.close = () => browserServer.close();

@@ -66,0 +70,0 @@ return browserContext;

@@ -104,13 +104,10 @@ "use strict";

}
pageProxy.page().then(async (page) => {
if (!page)
return;
context.emit(events_1.Events.BrowserContext.Page, new page_1.PageEvent(page));
if (!opener)
return;
const openerPage = await opener.page();
if (!openerPage || page.isClosed())
return;
openerPage.emit(events_1.Events.Page.Popup, page);
}).catch(helper_1.debugError); // Just not emit the event in case of initialization failure.
const pageEvent = new page_1.PageEvent(pageProxy.pageOrError());
context.emit(events_1.Events.BrowserContext.Page, pageEvent);
if (!opener)
return;
opener.pageOrError().then(openerPage => {
if (openerPage instanceof page_1.Page && !openerPage.isClosed())
openerPage.emit(events_1.Events.Page.Popup, pageEvent);
});
}

@@ -195,4 +192,4 @@ _onPageProxyDestroyed(event) {

const pageProxies = Array.from(this._browser._pageProxies.values()).filter(proxy => proxy._browserContext === this);
const pages = await Promise.all(pageProxies.map(proxy => proxy.page()));
return pages.filter(page => !!page);
const pages = await Promise.all(pageProxies.map(proxy => proxy.pageOrError()));
return pages.filter(page => page instanceof page_1.Page && !page.isClosed());
}

@@ -203,4 +200,9 @@ async newPage() {

const pageProxy = this._browser._pageProxies.get(pageProxyId);
const page = await pageProxy.page();
return page;
const result = await pageProxy.pageOrError();
if (result instanceof page_1.Page) {
if (result.isClosed())
throw new Error('Page has been closed.');
return result;
}
throw result;
}

@@ -207,0 +209,0 @@ async cookies(...urls) {

@@ -376,4 +376,8 @@ "use strict";

async opener() {
const openerPage = this._opener ? await this._opener.page() : null;
return openerPage && !openerPage.isClosed() ? openerPage : null;
if (!this._opener)
return null;
const openerPage = await this._opener.pageOrError();
if (openerPage instanceof page_1.Page && !openerPage.isClosed())
return openerPage;
return null;
}

@@ -380,0 +384,0 @@ async reload() {

@@ -25,4 +25,3 @@ /**

private readonly _pagePromise;
private _pagePromiseFulfill;
private _pagePromiseReject;
private _pagePromiseCallback;
private readonly _wkPage;

@@ -38,3 +37,3 @@ private _initialized;

handleProvisionalLoadFailed(event: Protocol.Browser.provisionalLoadFailedPayload): void;
page(): Promise<Page | null>;
pageOrError(): Promise<Page | Error>;
existingPage(): Page | undefined;

@@ -41,0 +40,0 @@ private _onTargetCreated;

@@ -24,4 +24,3 @@ "use strict";

constructor(pageProxySession, browserContext, opener) {
this._pagePromiseFulfill = () => { };
this._pagePromiseReject = () => { };
this._pagePromiseCallback = () => { };
this._initialized = false;

@@ -38,6 +37,3 @@ this._sessions = new Map();

];
this._pagePromise = new Promise((f, r) => {
this._pagePromiseFulfill = f;
this._pagePromiseReject = r;
});
this._pagePromise = new Promise(f => this._pagePromiseCallback = f);
this._wkPage = new wkPage_1.WKPage(this._browserContext, this._pageProxySession, this._opener);

@@ -77,3 +73,3 @@ }

}
async page() {
async pageOrError() {
return this._pagePromise;

@@ -98,18 +94,13 @@ }

this._initialized = true;
let page = null;
let error;
let pageOrError;
try {
await this._wkPage.initialize(session);
page = this._wkPage._page;
pageOrError = this._wkPage._page;
}
catch (e) {
if (!this._pageProxySession.isDisposed())
error = e;
pageOrError = e;
}
if (targetInfo.isPaused)
this._resumeTarget(targetInfo.targetId);
if (error)
this._pagePromiseReject(error);
else
this._pagePromiseFulfill(page);
this._pagePromiseCallback(pageOrError);
}

@@ -116,0 +107,0 @@ else {

{
"name": "playwright-core",
"version": "0.11.1-next.1583449329858",
"version": "0.11.1-next.1583451168969",
"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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc