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
4701
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.1583521768218 to 0.11.1-next.1583531345180

8

lib/webkit/wkBrowser.d.ts

@@ -26,3 +26,3 @@ /**

import { PageProxyMessageReceivedPayload, WKSession } from './wkConnection';
import { WKPageProxy } from './wkPageProxy';
import { WKPage } from './wkPage';
export declare class WKBrowser extends platform.EventEmitter implements Browser {

@@ -34,6 +34,6 @@ private readonly _connection;

readonly _contexts: Map<string, WKBrowserContext>;
readonly _pageProxies: Map<string, WKPageProxy>;
readonly _wkPages: Map<string, WKPage>;
private readonly _eventListeners;
private _firstPageProxyCallback?;
private readonly _firstPageProxyPromise;
private _firstPageCallback?;
private readonly _firstPagePromise;
static connect(transport: ConnectionTransport, slowMo?: number, attachToDefaultContext?: boolean): Promise<WKBrowser>;

@@ -40,0 +40,0 @@ constructor(transport: ConnectionTransport, attachToDefaultContext: boolean);

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

const wkConnection_1 = require("./wkConnection");
const wkPageProxy_1 = require("./wkPageProxy");
const wkPage_1 = require("./wkPage");
const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15';

@@ -35,3 +35,3 @@ class WKBrowser extends platform.EventEmitter {

this._contexts = new Map();
this._pageProxies = new Map();
this._wkPages = new Map();
this._connection = new wkConnection_1.WKConnection(transport, this._onDisconnect.bind(this));

@@ -47,3 +47,3 @@ this._attachToDefaultContext = attachToDefaultContext;

];
this._firstPageProxyPromise = new Promise(resolve => this._firstPageProxyCallback = resolve);
this._firstPagePromise = new Promise(resolve => this._firstPageCallback = resolve);
}

@@ -57,5 +57,5 @@ static async connect(transport, slowMo = 0, attachToDefaultContext = false) {

context._browserClosed();
for (const pageProxy of this._pageProxies.values())
pageProxy.dispose();
this._pageProxies.clear();
for (const wkPage of this._wkPages.values())
wkPage.dispose();
this._wkPages.clear();
this.emit(events_1.Events.Browser.Disconnected);

@@ -79,4 +79,4 @@ }

async _waitForFirstPageTarget() {
helper_1.assert(!this._pageProxies.size);
return this._firstPageProxyPromise;
helper_1.assert(!this._wkPages.size);
return this._firstPagePromise;
}

@@ -101,10 +101,10 @@ _onPageProxyCreated(event) {

});
const opener = pageProxyInfo.openerId ? this._pageProxies.get(pageProxyInfo.openerId) : undefined;
const pageProxy = new wkPageProxy_1.WKPageProxy(pageProxySession, context, opener || null);
this._pageProxies.set(pageProxyId, pageProxy);
if (this._firstPageProxyCallback) {
this._firstPageProxyCallback();
this._firstPageProxyCallback = undefined;
const opener = pageProxyInfo.openerId ? this._wkPages.get(pageProxyInfo.openerId) : undefined;
const wkPage = new wkPage_1.WKPage(context, pageProxySession, opener || null);
this._wkPages.set(pageProxyId, wkPage);
if (this._firstPageCallback) {
this._firstPageCallback();
this._firstPageCallback = undefined;
}
const pageEvent = new page_1.PageEvent(pageProxy.pageOrError());
const pageEvent = new page_1.PageEvent(wkPage.pageOrError());
context.emit(events_1.Events.BrowserContext.Page, pageEvent);

@@ -120,20 +120,20 @@ if (!opener)

const pageProxyId = event.pageProxyId;
const pageProxy = this._pageProxies.get(pageProxyId);
if (!pageProxy)
const wkPage = this._wkPages.get(pageProxyId);
if (!wkPage)
return;
pageProxy.didClose();
pageProxy.dispose();
this._pageProxies.delete(pageProxyId);
wkPage.didClose(false);
wkPage.dispose();
this._wkPages.delete(pageProxyId);
}
_onPageProxyMessageReceived(event) {
const pageProxy = this._pageProxies.get(event.pageProxyId);
if (!pageProxy)
const wkPage = this._wkPages.get(event.pageProxyId);
if (!wkPage)
return;
pageProxy.dispatchMessageToSession(event.message);
wkPage.dispatchMessageToSession(event.message);
}
_onProvisionalLoadFailed(event) {
const pageProxy = this._pageProxies.get(event.pageProxyId);
if (!pageProxy)
const wkPage = this._wkPages.get(event.pageProxyId);
if (!wkPage)
return;
pageProxy.handleProvisionalLoadFailed(event);
wkPage.handleProvisionalLoadFailed(event);
}

@@ -176,6 +176,6 @@ isConnected() {

const pages = [];
for (const pageProxy of this._browser._pageProxies.values()) {
if (pageProxy._browserContext !== this)
for (const wkPage of this._browser._wkPages.values()) {
if (wkPage._browserContext !== this)
continue;
const page = pageProxy.existingPage();
const page = wkPage._initializedPage();
if (page)

@@ -187,4 +187,4 @@ pages.push(page);

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

@@ -195,4 +195,4 @@ }

const { pageProxyId } = await this._browser._browserSession.send('Browser.createPage', { browserContextId: this._browserContextId });
const pageProxy = this._browser._pageProxies.get(pageProxyId);
const result = await pageProxy.pageOrError();
const wkPage = this._browser._wkPages.get(pageProxyId);
const result = await wkPage.pageOrError();
if (result instanceof page_1.Page) {

@@ -199,0 +199,0 @@ if (result.isClosed())

@@ -27,3 +27,2 @@ /**

import * as platform from '../platform';
import { WKPageProxy } from './wkPageProxy';
import { WKBrowserContext } from './wkBrowser';

@@ -36,2 +35,4 @@ export declare class WKPage implements PageDelegate {

readonly _page: Page;
private readonly _pagePromise;
private _pagePromiseCallback;
private readonly _pageProxySession;

@@ -44,15 +45,22 @@ private readonly _opener;

private _sessionListeners;
private _eventListeners;
private readonly _evaluateOnNewDocumentSources;
private readonly _browserContext;
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPageProxy | null);
readonly _browserContext: WKBrowserContext;
private _initialized;
private readonly _sessions;
constructor(browserContext: WKBrowserContext, pageProxySession: WKSession, opener: WKPage | null);
_initializedPage(): Page | undefined;
private _initializePageProxySession;
private _setSession;
initialize(session: WKSession): Promise<void>;
_initializeSession(session: WKSession, resourceTreeHandler: (r: Protocol.Page.getResourceTreeReturnValue) => void): Promise<void>;
private _initializeSessionMayThrow;
initializeProvisionalPage(provisionalSession: WKSession): Promise<void>;
onProvisionalLoadCommitted(session: WKSession): void;
onSessionDestroyed(session: WKSession, crashed: boolean): void;
private _onDidCommitProvisionalTarget;
private _onTargetDestroyed;
didClose(crashed: boolean): void;
dispose(): void;
dispatchMessageToSession(message: any): void;
handleProvisionalLoadFailed(event: Protocol.Browser.provisionalLoadFailedPayload): void;
pageOrError(): Promise<Page | Error>;
private _onTargetCreated;
private _onDispatchMessageFromTarget;
private _addSessionListeners;

@@ -59,0 +67,0 @@ private _updateState;

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

const network = require("../network");
const wkConnection_1 = require("./wkConnection");
const events_1 = require("../events");

@@ -35,8 +36,13 @@ const wkExecutionContext_1 = require("./wkExecutionContext");

const BINDING_CALL_MESSAGE = '__playwright_binding_call__';
const isPovisionalSymbol = Symbol('isPovisional');
class WKPage {
constructor(browserContext, pageProxySession, opener) {
this._provisionalPage = null;
this._pagePromiseCallback = () => { };
this._requestIdToRequest = new Map();
this._sessionListeners = [];
this._evaluateOnNewDocumentSources = [];
this._initialized = false;
// TODO: we should be able to just use |this._session| and |this._provisionalPage|.
this._sessions = new Map();
this._pageProxySession = pageProxySession;

@@ -52,3 +58,13 @@ this._opener = opener;

this._page.on(events_1.Events.Page.FrameDetached, frame => this._removeContextsForFrame(frame, false));
this._eventListeners = [
helper_1.helper.addEventListener(this._pageProxySession, 'Target.targetCreated', this._onTargetCreated.bind(this)),
helper_1.helper.addEventListener(this._pageProxySession, 'Target.targetDestroyed', this._onTargetDestroyed.bind(this)),
helper_1.helper.addEventListener(this._pageProxySession, 'Target.dispatchMessageFromTarget', this._onDispatchMessageFromTarget.bind(this)),
helper_1.helper.addEventListener(this._pageProxySession, 'Target.didCommitProvisionalTarget', this._onDidCommitProvisionalTarget.bind(this)),
];
this._pagePromise = new Promise(f => this._pagePromiseCallback = f);
}
_initializedPage() {
return this._initialized ? this._page : undefined;
}
async _initializePageProxySession() {

@@ -74,9 +90,2 @@ const promises = [

}
async initialize(session) {
this._setSession(session);
await Promise.all([
this._initializePageProxySession(),
this._initializeSession(this._session, ({ frameTree }) => this._handleFrameTree(frameTree)),
]);
}
// This method is called for provisional targets as well. The session passed as the parameter

@@ -132,16 +141,23 @@ // may be different from the current session and may be destroyed without becoming current.

}
initializeProvisionalPage(provisionalSession) {
helper_1.assert(!this._provisionalPage);
this._provisionalPage = new wkProvisionalPage_1.WKProvisionalPage(provisionalSession, this);
return this._provisionalPage.initializationPromise;
}
onProvisionalLoadCommitted(session) {
_onDidCommitProvisionalTarget(event) {
const { oldTargetId, newTargetId } = event;
const newSession = this._sessions.get(newTargetId);
helper_1.assert(newSession, 'Unknown new target: ' + newTargetId);
const oldSession = this._sessions.get(oldTargetId);
helper_1.assert(oldSession, 'Unknown old target: ' + oldTargetId);
oldSession.errorText = 'Target was swapped out.';
newSession[isPovisionalSymbol] = undefined;
helper_1.assert(this._provisionalPage);
helper_1.assert(this._provisionalPage._session === session);
helper_1.assert(this._provisionalPage._session === newSession);
this._provisionalPage.commit();
this._provisionalPage.dispose();
this._provisionalPage = null;
this._setSession(session);
this._setSession(newSession);
}
onSessionDestroyed(session, crashed) {
_onTargetDestroyed(event) {
const { targetId, crashed } = event;
const session = this._sessions.get(targetId);
helper_1.assert(session, 'Unknown target destroyed: ' + targetId);
session.dispose();
this._sessions.delete(targetId);
if (this._provisionalPage && this._provisionalPage._session === session) {

@@ -163,2 +179,7 @@ this._provisionalPage.dispose();

dispose() {
this._pageProxySession.dispose();
helper_1.helper.removeEventListeners(this._eventListeners);
for (const session of this._sessions.values())
session.dispose();
this._sessions.clear();
if (this._provisionalPage) {

@@ -170,2 +191,64 @@ this._provisionalPage.dispose();

}
dispatchMessageToSession(message) {
this._pageProxySession.dispatchMessage(message);
}
handleProvisionalLoadFailed(event) {
if (!this._initialized || !this._provisionalPage)
return;
let errorText = event.error;
if (errorText.includes('cancelled'))
errorText += '; maybe frame was detached?';
this._page._frameManager.provisionalLoadFailed(this._page.mainFrame(), event.loaderId, errorText);
}
async pageOrError() {
return this._pagePromise;
}
async _onTargetCreated(event) {
const { targetInfo } = event;
const session = new wkConnection_1.WKSession(this._pageProxySession.connection, targetInfo.targetId, `The ${targetInfo.type} has been closed.`, (message) => {
this._pageProxySession.send('Target.sendMessageToTarget', {
message: JSON.stringify(message), targetId: targetInfo.targetId
}).catch(e => {
session.dispatchMessage({ id: message.id, error: { message: e.message } });
});
});
helper_1.assert(targetInfo.type === 'page', 'Only page targets are expected in WebKit, received: ' + targetInfo.type);
this._sessions.set(targetInfo.targetId, session);
if (!this._initialized) {
helper_1.assert(!targetInfo.isProvisional);
let pageOrError;
try {
this._setSession(session);
await Promise.all([
this._initializePageProxySession(),
this._initializeSession(session, ({ frameTree }) => this._handleFrameTree(frameTree)),
]);
pageOrError = this._page;
}
catch (e) {
pageOrError = e;
}
if (targetInfo.isPaused)
this._pageProxySession.send('Target.resume', { targetId: targetInfo.targetId }).catch(helper_1.debugError);
this._initialized = true;
this._pagePromiseCallback(pageOrError);
}
else {
helper_1.assert(targetInfo.isProvisional);
session[isPovisionalSymbol] = true;
helper_1.assert(!this._provisionalPage);
this._provisionalPage = new wkProvisionalPage_1.WKProvisionalPage(session, this);
if (targetInfo.isPaused) {
this._provisionalPage.initializationPromise.then(() => {
this._pageProxySession.send('Target.resume', { targetId: targetInfo.targetId }).catch(helper_1.debugError);
});
}
}
}
_onDispatchMessageFromTarget(event) {
const { targetId, message } = event;
const session = this._sessions.get(targetId);
helper_1.assert(session, 'Unknown target: ' + targetId);
session.dispatchMessage(JSON.parse(message));
}
_addSessionListeners() {

@@ -172,0 +255,0 @@ this._sessionListeners = [

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