playwright-core
Advanced tools
Comparing version
@@ -57,2 +57,3 @@ /** | ||
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>; | ||
waitForEvent(event: string, optionsOrPredicate?: Function | (types.TimeoutOptions & { | ||
@@ -67,2 +68,6 @@ predicate?: Function; | ||
readonly _options: BrowserContextOptions; | ||
readonly _routes: { | ||
url: types.URLMatch; | ||
handler: (request: network.Request) => any; | ||
}[]; | ||
_closed: boolean; | ||
@@ -91,2 +96,3 @@ private readonly _closePromise; | ||
abstract exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
abstract route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>; | ||
abstract close(): Promise<void>; | ||
@@ -93,0 +99,0 @@ setDefaultNavigationTimeout(timeout: number): void; |
@@ -29,2 +29,3 @@ "use strict"; | ||
this._pageBindings = new Map(); | ||
this._routes = []; | ||
this._closed = false; | ||
@@ -31,0 +32,0 @@ this._options = options; |
@@ -86,2 +86,3 @@ /** | ||
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>; | ||
close(): Promise<void>; | ||
@@ -88,0 +89,0 @@ backgroundPages(): Promise<Page[]>; |
@@ -342,2 +342,7 @@ "use strict"; | ||
} | ||
async route(url, handler) { | ||
this._routes.push({ url, handler }); | ||
for (const page of this._existingPages()) | ||
await page._delegate.updateRequestInterception(); | ||
} | ||
async close() { | ||
@@ -344,0 +349,0 @@ if (this._closed) |
@@ -74,3 +74,3 @@ /** | ||
setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void>; | ||
setRequestInterception(enabled: boolean): Promise<void>; | ||
updateRequestInterception(): Promise<void>; | ||
setFileChooserIntercepted(enabled: boolean): Promise<void>; | ||
@@ -77,0 +77,0 @@ opener(): Promise<Page | null>; |
@@ -104,2 +104,3 @@ "use strict"; | ||
promises.push(this.updateExtraHTTPHeaders()); | ||
promises.push(this.updateRequestInterception()); | ||
if (options.offline) | ||
@@ -326,4 +327,4 @@ promises.push(this._networkManager.setOffline(options.offline)); | ||
} | ||
async setRequestInterception(enabled) { | ||
await this._networkManager.setRequestInterception(enabled); | ||
async updateRequestInterception() { | ||
await this._networkManager.setRequestInterception(this._page._needsRequestInterception()); | ||
} | ||
@@ -330,0 +331,0 @@ async setFileChooserIntercepted(enabled) { |
@@ -72,3 +72,4 @@ /** | ||
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>; | ||
close(): Promise<void>; | ||
} |
@@ -249,2 +249,7 @@ "use strict"; | ||
} | ||
async route(url, handler) { | ||
this._routes.push({ url, handler }); | ||
throw new Error('Not implemented'); | ||
// TODO: update interception on the context if this is a first route. | ||
} | ||
async close() { | ||
@@ -251,0 +256,0 @@ if (this._closed) |
@@ -71,3 +71,3 @@ /** | ||
setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void>; | ||
setRequestInterception(enabled: boolean): Promise<void>; | ||
updateRequestInterception(): Promise<void>; | ||
setFileChooserIntercepted(enabled: boolean): Promise<void>; | ||
@@ -74,0 +74,0 @@ opener(): Promise<Page | null>; |
@@ -257,4 +257,4 @@ "use strict"; | ||
} | ||
async setRequestInterception(enabled) { | ||
await this._networkManager.setRequestInterception(enabled); | ||
async updateRequestInterception() { | ||
await this._networkManager.setRequestInterception(this._page._needsRequestInterception()); | ||
} | ||
@@ -261,0 +261,0 @@ async setFileChooserIntercepted(enabled) { |
@@ -39,2 +39,3 @@ /** | ||
}; | ||
export declare type RouteHandler = (request: Request) => void; | ||
export declare function filterCookies(cookies: NetworkCookie[], urls?: string | string[]): NetworkCookie[]; | ||
@@ -41,0 +42,0 @@ export declare function rewriteCookies(cookies: SetNetworkCookieParam[]): SetNetworkCookieParam[]; |
@@ -43,3 +43,3 @@ /** | ||
setEmulateMedia(mediaType: types.MediaType | null, colorScheme: types.ColorScheme | null): Promise<void>; | ||
setRequestInterception(enabled: boolean): Promise<void>; | ||
updateRequestInterception(): Promise<void>; | ||
setFileChooserIntercepted(enabled: boolean): Promise<void>; | ||
@@ -81,4 +81,2 @@ canScreenshotOutsideViewport(): boolean; | ||
extraHTTPHeaders: network.Headers | null; | ||
interceptNetwork: boolean | null; | ||
hasTouch: boolean | null; | ||
}; | ||
@@ -114,5 +112,5 @@ export declare type FileChooser = { | ||
readonly coverage: any; | ||
readonly _requestHandlers: { | ||
readonly _routes: { | ||
url: types.URLMatch; | ||
handler: (request: network.Request) => void; | ||
handler: (request: network.Request) => any; | ||
}[]; | ||
@@ -181,3 +179,4 @@ _ownedContext: BrowserContext | undefined; | ||
}, ...args: any[]): Promise<void>; | ||
route(url: types.URLMatch, handler: (request: network.Request) => void): Promise<void>; | ||
_needsRequestInterception(): boolean; | ||
route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>; | ||
_requestStarted(request: network.Request): void; | ||
@@ -184,0 +183,0 @@ screenshot(options?: types.ScreenshotOptions): Promise<platform.BufferType>; |
@@ -53,3 +53,3 @@ "use strict"; | ||
this._workers = new Map(); | ||
this._requestHandlers = []; | ||
this._routes = []; | ||
this.evaluateHandle = async (pageFunction, ...args) => { | ||
@@ -85,4 +85,2 @@ return this.mainFrame().evaluateHandle(pageFunction, ...args); | ||
extraHTTPHeaders: null, | ||
interceptNetwork: null, | ||
hasTouch: null, | ||
}; | ||
@@ -274,8 +272,8 @@ this.accessibility = new accessibility.Accessibility(delegate.getAccessibilityTree.bind(delegate)); | ||
} | ||
_needsRequestInterception() { | ||
return this._routes.length > 0 || this._browserContext._routes.length > 0; | ||
} | ||
async route(url, handler) { | ||
if (!this._state.interceptNetwork) { | ||
this._state.interceptNetwork = true; | ||
await this._delegate.setRequestInterception(true); | ||
} | ||
this._requestHandlers.push({ url, handler }); | ||
this._routes.push({ url, handler }); | ||
await this._delegate.updateRequestInterception(); | ||
} | ||
@@ -286,3 +284,3 @@ _requestStarted(request) { | ||
return; | ||
for (const { url, handler } of this._requestHandlers) { | ||
for (const { url, handler } of this._routes) { | ||
if (platform.urlMatches(request.url(), url)) { | ||
@@ -293,2 +291,8 @@ handler(request); | ||
} | ||
for (const { url, handler } of this._browserContext._routes) { | ||
if (platform.urlMatches(request.url(), url)) { | ||
handler(request); | ||
return; | ||
} | ||
} | ||
request.continue(); | ||
@@ -295,0 +299,0 @@ } |
@@ -76,3 +76,4 @@ /** | ||
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>; | ||
close(): Promise<void>; | ||
} |
@@ -267,2 +267,7 @@ "use strict"; | ||
} | ||
async route(url, handler) { | ||
this._routes.push({ url, handler }); | ||
for (const page of this._existingPages()) | ||
await page._delegate.updateRequestInterception(); | ||
} | ||
async close() { | ||
@@ -269,0 +274,0 @@ if (this._closed) |
@@ -84,4 +84,4 @@ /** | ||
setViewportSize(viewportSize: types.Size): Promise<void>; | ||
_updateViewport(updateTouch: boolean): Promise<void>; | ||
setRequestInterception(enabled: boolean): Promise<void>; | ||
_updateViewport(): Promise<void>; | ||
updateRequestInterception(): Promise<void>; | ||
updateOffline(): Promise<void>; | ||
@@ -88,0 +88,0 @@ updateHttpCredentials(): Promise<void>; |
@@ -73,3 +73,3 @@ "use strict"; | ||
if (this._page._state.viewportSize || contextOptions.viewport) | ||
promises.push(this._updateViewport(true /* updateTouch */)); | ||
promises.push(this._updateViewport()); | ||
promises.push(this.updateHttpCredentials()); | ||
@@ -112,3 +112,3 @@ await Promise.all(promises); | ||
]; | ||
if (this._page._state.interceptNetwork) | ||
if (this._page._needsRequestInterception()) | ||
promises.push(session.send('Network.setInterceptionEnabled', { enabled: true, interceptRequests: true })); | ||
@@ -128,4 +128,3 @@ const contextOptions = this._browserContext._options; | ||
promises.push(session.send('Network.setEmulateOfflineState', { offline: true })); | ||
if (this._page._state.hasTouch) | ||
promises.push(session.send('Page.setTouchEmulationEnabled', { enabled: true })); | ||
promises.push(session.send('Page.setTouchEmulationEnabled', { enabled: contextOptions.viewport ? !!contextOptions.viewport.isMobile : false })); | ||
if (contextOptions.timezoneId) { | ||
@@ -422,5 +421,5 @@ promises.push(session.send('Page.setTimeZone', { timeZone: contextOptions.timezoneId }). | ||
helper_1.assert(this._page._state.viewportSize === viewportSize); | ||
await this._updateViewport(false /* updateTouch */); | ||
await this._updateViewport(); | ||
} | ||
async _updateViewport(updateTouch) { | ||
async _updateViewport() { | ||
let viewport = this._browserContext._options.viewport || { width: 0, height: 0 }; | ||
@@ -438,7 +437,6 @@ const viewportSize = this._page._state.viewportSize; | ||
]; | ||
if (updateTouch) | ||
promises.push(this._updateState('Page.setTouchEmulationEnabled', { enabled: !!viewport.isMobile })); | ||
await Promise.all(promises); | ||
} | ||
async setRequestInterception(enabled) { | ||
async updateRequestInterception() { | ||
const enabled = this._page._needsRequestInterception(); | ||
await this._updateState('Network.setInterceptionEnabled', { enabled, interceptRequests: enabled }); | ||
@@ -650,3 +648,3 @@ } | ||
const documentId = isNavigationRequest ? event.loaderId : undefined; | ||
const request = new wkInterceptableRequest_1.WKInterceptableRequest(session, !!this._page._state.interceptNetwork, frame, event, redirectChain, documentId); | ||
const request = new wkInterceptableRequest_1.WKInterceptableRequest(session, this._page._needsRequestInterception(), frame, event, redirectChain, documentId); | ||
this._requestIdToRequest.set(event.requestId, request); | ||
@@ -653,0 +651,0 @@ this._page._frameManager.requestStarted(request.request); |
{ | ||
"name": "playwright-core", | ||
"version": "0.11.1-next.1583805691762", | ||
"version": "0.11.1-next.1583813990795", | ||
"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
2443622
0.08%57277
0.08%