playwright-core
Advanced tools
Comparing version 0.11.1-next.1583792051156 to 0.11.1-next.1583796504588
@@ -42,4 +42,5 @@ /** | ||
newPage(options?: BrowserContextOptions): Promise<Page>; | ||
_onAttachedToTarget(event: Protocol.Target.attachedToTargetPayload): Promise<void>; | ||
_onAttachedToTarget({ targetInfo, sessionId, waitingForDebugger }: Protocol.Target.attachedToTargetPayload): Promise<void>; | ||
_targetCreated({ targetInfo }: Protocol.Target.targetCreatedPayload): Promise<void>; | ||
private _createTarget; | ||
_targetDestroyed(event: { | ||
@@ -46,0 +47,0 @@ targetId: string; |
@@ -90,15 +90,15 @@ "use strict"; | ||
} | ||
async _onAttachedToTarget(event) { | ||
if (!crTarget_1.CRTarget.isPageType(event.targetInfo.type)) | ||
async _onAttachedToTarget({ targetInfo, sessionId, waitingForDebugger }) { | ||
const session = this._connection.session(sessionId); | ||
if (!crTarget_1.CRTarget.isPageType(targetInfo.type)) { | ||
helper_1.assert(targetInfo.type === 'service_worker' || targetInfo.type === 'browser' || targetInfo.type === 'other'); | ||
if (waitingForDebugger) { | ||
// Ideally, detaching should resume any target, but there is a bug in the backend. | ||
session.send('Runtime.runIfWaitingForDebugger').catch(helper_1.debugError).then(() => { | ||
this._session.send('Target.detachFromTarget', { sessionId }).catch(helper_1.debugError); | ||
}); | ||
} | ||
return; | ||
const target = this._targets.get(event.targetInfo.targetId); | ||
const session = this._connection.session(event.sessionId); | ||
await target.initializePageSession(session).catch(helper_1.debugError); | ||
} | ||
async _targetCreated({ targetInfo }) { | ||
const { browserContextId } = targetInfo; | ||
const context = (browserContextId && this._contexts.has(browserContextId)) ? this._contexts.get(browserContextId) : this._defaultContext; | ||
const target = new crTarget_1.CRTarget(this, targetInfo, context, () => this._connection.createSession(targetInfo)); | ||
helper_1.assert(!this._targets.has(targetInfo.targetId), 'Target should not exist before targetCreated'); | ||
this._targets.set(targetInfo.targetId, target); | ||
} | ||
const { context, target } = this._createTarget(targetInfo, session); | ||
try { | ||
@@ -122,7 +122,2 @@ switch (targetInfo.type) { | ||
} | ||
case 'service_worker': { | ||
const serviceWorker = await target.serviceWorker(); | ||
context.emit(events_2.Events.CRBrowserContext.ServiceWorker, serviceWorker); | ||
break; | ||
} | ||
} | ||
@@ -135,4 +130,21 @@ } | ||
} | ||
async _targetCreated({ targetInfo }) { | ||
if (targetInfo.type !== 'service_worker') | ||
return; | ||
const { context, target } = this._createTarget(targetInfo, null); | ||
const serviceWorker = await target.serviceWorker(); | ||
context.emit(events_2.Events.CRBrowserContext.ServiceWorker, serviceWorker); | ||
} | ||
_createTarget(targetInfo, session) { | ||
const { browserContextId } = targetInfo; | ||
const context = (browserContextId && this._contexts.has(browserContextId)) ? this._contexts.get(browserContextId) : this._defaultContext; | ||
const target = new crTarget_1.CRTarget(this, targetInfo, context, session, () => this._connection.createSession(targetInfo)); | ||
helper_1.assert(!this._targets.has(targetInfo.targetId), 'Target should not exist before targetCreated'); | ||
this._targets.set(targetInfo.targetId, target); | ||
return { context, target }; | ||
} | ||
async _targetDestroyed(event) { | ||
const target = this._targets.get(event.targetId); | ||
if (!target) | ||
return; | ||
this._targets.delete(event.targetId); | ||
@@ -143,3 +155,4 @@ target._didClose(); | ||
const target = this._targets.get(event.targetInfo.targetId); | ||
helper_1.assert(target, 'target should exist before targetInfoChanged'); | ||
if (!target) | ||
return; | ||
target._targetInfoChanged(event.targetInfo); | ||
@@ -146,0 +159,0 @@ } |
@@ -23,3 +23,2 @@ /** | ||
import * as frames from '../frames'; | ||
import * as platform from '../platform'; | ||
import { Credentials } from '../types'; | ||
@@ -67,10 +66,5 @@ export declare class CRNetworkManager { | ||
}): Promise<void>; | ||
fulfill(response: { | ||
status: number; | ||
headers: network.Headers; | ||
contentType: string; | ||
body: (string | platform.BufferType); | ||
}): Promise<void>; | ||
fulfill(response: network.FulfillResponse): Promise<void>; | ||
abort(errorCode?: string): Promise<void>; | ||
} | ||
export {}; |
@@ -311,2 +311,4 @@ "use strict"; | ||
height: viewport.height, | ||
screenWidth: viewport.width, | ||
screenHeight: viewport.height, | ||
deviceScaleFactor: viewport.deviceScaleFactor || 1, | ||
@@ -313,0 +315,0 @@ screenOrientation: isLandscape ? { angle: 90, type: 'landscapePrimary' } : { angle: 0, type: 'portraitPrimary' }, |
@@ -34,5 +34,4 @@ /** | ||
static isPageType(type: string): boolean; | ||
constructor(browser: CRBrowser, targetInfo: Protocol.Target.TargetInfo, browserContext: CRBrowserContext, sessionFactory: () => Promise<CRSession>); | ||
constructor(browser: CRBrowser, targetInfo: Protocol.Target.TargetInfo, browserContext: CRBrowserContext, session: CRSession | null, sessionFactory: () => Promise<CRSession>); | ||
_didClose(): void; | ||
initializePageSession(session: CRSession): Promise<void>; | ||
pageOrError(): Promise<Page | Error>; | ||
@@ -39,0 +38,0 @@ serviceWorker(): Promise<Worker | null>; |
@@ -26,3 +26,3 @@ "use strict"; | ||
class CRTarget { | ||
constructor(browser, targetInfo, browserContext, sessionFactory) { | ||
constructor(browser, targetInfo, browserContext, session, sessionFactory) { | ||
this._pagePromiseCallback = null; | ||
@@ -37,4 +37,10 @@ this._pagePromise = null; | ||
this.sessionFactory = sessionFactory; | ||
if (CRTarget.isPageType(targetInfo.type)) | ||
this._pagePromise = new Promise(f => this._pagePromiseCallback = f); | ||
if (CRTarget.isPageType(targetInfo.type)) { | ||
helper_1.assert(session, 'Page target must be created with existing session'); | ||
this._crPage = new crPage_1.CRPage(session, this._browser, this._browserContext); | ||
const page = this._crPage.page(); | ||
page[targetSymbol] = this; | ||
session.once(crConnection_1.CRSessionEvents.Disconnected, () => page._didDisconnect()); | ||
this._pagePromise = this._crPage.initialize().then(() => page).catch(e => e); | ||
} | ||
} | ||
@@ -51,19 +57,6 @@ static fromPage(page) { | ||
} | ||
async initializePageSession(session) { | ||
this._crPage = new crPage_1.CRPage(session, this._browser, this._browserContext); | ||
const page = this._crPage.page(); | ||
page[targetSymbol] = this; | ||
session.once(crConnection_1.CRSessionEvents.Disconnected, () => page._didDisconnect()); | ||
try { | ||
await this._crPage.initialize(); | ||
this._pagePromiseCallback(page); | ||
} | ||
catch (e) { | ||
this._pagePromiseCallback(e); | ||
} | ||
} | ||
async pageOrError() { | ||
if (this._targetInfo.type !== 'page' && this._targetInfo.type !== 'background_page') | ||
throw new Error('Not a page.'); | ||
return this._pagePromise; | ||
if (CRTarget.isPageType(this.type())) | ||
return this._pagePromise; | ||
throw new Error('Not a page.'); | ||
} | ||
@@ -70,0 +63,0 @@ async serviceWorker() { |
@@ -83,7 +83,4 @@ /** | ||
abort(errorCode?: string): Promise<void>; | ||
fulfill(response: { | ||
status: number; | ||
headers: Headers; | ||
contentType: string; | ||
body: (string | platform.BufferType); | ||
fulfill(response: FulfillResponse & { | ||
path?: string; | ||
}): Promise<void>; | ||
@@ -122,10 +119,11 @@ continue(overrides?: { | ||
} | ||
export declare type FulfillResponse = { | ||
status?: number; | ||
headers?: Headers; | ||
contentType?: string; | ||
body?: string | platform.BufferType; | ||
}; | ||
export interface RequestDelegate { | ||
abort(errorCode: string): Promise<void>; | ||
fulfill(response: { | ||
status: number; | ||
headers: Headers; | ||
contentType: string; | ||
body: (string | platform.BufferType); | ||
}): Promise<void>; | ||
fulfill(response: FulfillResponse): Promise<void>; | ||
continue(overrides: { | ||
@@ -132,0 +130,0 @@ method?: string; |
@@ -19,2 +19,3 @@ "use strict"; | ||
const helper_1 = require("./helper"); | ||
const platform = require("./platform"); | ||
function filterCookies(cookies, urls = []) { | ||
@@ -151,2 +152,10 @@ if (!Array.isArray(urls)) | ||
this._interceptionHandled = true; | ||
if (response.path) { | ||
response = { | ||
status: response.status, | ||
headers: response.headers, | ||
contentType: platform.getMimeType(response.path), | ||
body: await platform.readFileBuffer(response.path) | ||
}; | ||
} | ||
await this._delegate.fulfill(response); | ||
@@ -153,0 +162,0 @@ } |
@@ -32,2 +32,3 @@ /** | ||
export declare function readFileAsync(file: string, encoding: string): Promise<string>; | ||
export declare function readFileBuffer(file: string): Promise<BufferType>; | ||
export declare function writeFileAsync(file: string, data: any): Promise<any>; | ||
@@ -34,0 +35,0 @@ export declare function basename(file: string): string; |
@@ -164,2 +164,7 @@ "use strict"; | ||
exports.readFileAsync = readFileAsync; | ||
async function readFileBuffer(file) { | ||
assertFileAccess(); | ||
return await promisify(nodeFS.readFile)(file); | ||
} | ||
exports.readFileBuffer = readFileBuffer; | ||
async function writeFileAsync(file, data) { | ||
@@ -166,0 +171,0 @@ assertFileAccess(); |
@@ -19,3 +19,2 @@ /** | ||
import * as network from '../network'; | ||
import * as platform from '../platform'; | ||
import { Protocol } from './protocol'; | ||
@@ -31,8 +30,3 @@ import { WKSession } from './wkConnection'; | ||
abort(errorCode: string): Promise<void>; | ||
fulfill(response: { | ||
status: number; | ||
headers: network.Headers; | ||
contentType: string; | ||
body: (string | platform.BufferType); | ||
}): Promise<void>; | ||
fulfill(response: network.FulfillResponse): Promise<void>; | ||
continue(overrides: { | ||
@@ -39,0 +33,0 @@ method?: string; |
{ | ||
"name": "playwright-core", | ||
"version": "0.11.1-next.1583792051156", | ||
"version": "0.11.1-next.1583796504588", | ||
"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
2440925
57202