mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: move more unsupported apis to interception (#91)
This commit is contained in:
parent
0494c4c04e
commit
c7a07ea2a8
31
docs/api.md
31
docs/api.md
@ -88,7 +88,6 @@
|
||||
* [page.accessibility](#pageaccessibility)
|
||||
* [page.addScriptTag(options)](#pageaddscripttagoptions)
|
||||
* [page.addStyleTag(options)](#pageaddstyletagoptions)
|
||||
* [page.authenticate(credentials)](#pageauthenticatecredentials)
|
||||
* [page.browser()](#pagebrowser)
|
||||
* [page.browserContext()](#pagebrowsercontext)
|
||||
* [page.click(selector[, options])](#pageclickselector-options)
|
||||
@ -127,7 +126,6 @@
|
||||
* [page.setDefaultTimeout(timeout)](#pagesetdefaulttimeouttimeout)
|
||||
* [page.setExtraHTTPHeaders(headers)](#pagesetextrahttpheadersheaders)
|
||||
* [page.setJavaScriptEnabled(enabled)](#pagesetjavascriptenabledenabled)
|
||||
* [page.setOfflineMode(enabled)](#pagesetofflinemodeenabled)
|
||||
* [page.setUserAgent(userAgent)](#pagesetuseragentuseragent)
|
||||
* [page.setViewport(viewport)](#pagesetviewportviewport)
|
||||
* [page.target()](#pagetarget)
|
||||
@ -232,10 +230,12 @@
|
||||
* [executionContext.frame()](#executioncontextframe)
|
||||
- [class: Interception](#class-interception)
|
||||
* [interception.abort(request, [errorCode])](#interceptionabortrequest-errorcode)
|
||||
* [interception.authenticate(credentials)](#interceptionauthenticatecredentials)
|
||||
* [interception.continue(request, [overrides])](#interceptioncontinuerequest-overrides)
|
||||
* [interception.disable()](#interceptiondisable)
|
||||
* [interception.enable()](#interceptionenable)
|
||||
* [interception.fulfill(request, response)](#interceptionfulfillrequest-response)
|
||||
* [interception.setOfflineMode(enabled)](#interceptionsetofflinemodeenabled)
|
||||
- [class: JSHandle](#class-jshandle)
|
||||
* [jsHandle.asElement()](#jshandleaselement)
|
||||
* [jsHandle.dispose()](#jshandledispose)
|
||||
@ -1119,16 +1119,6 @@ Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<s
|
||||
|
||||
Shortcut for [page.mainFrame().addStyleTag(options)](#frameaddstyletagoptions).
|
||||
|
||||
#### page.authenticate(credentials)
|
||||
- `credentials` <?[Object]>
|
||||
- `username` <[string]>
|
||||
- `password` <[string]>
|
||||
- returns: <[Promise]>
|
||||
|
||||
Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
|
||||
|
||||
To disable authentication, pass `null`.
|
||||
|
||||
#### page.browser()
|
||||
|
||||
- returns: <[Browser]>
|
||||
@ -1676,10 +1666,6 @@ The extra HTTP headers will be sent with every request the page initiates.
|
||||
|
||||
> **NOTE** changing this value won't affect scripts that have already been run. It will take full effect on the next [navigation](#pagegotourl-options).
|
||||
|
||||
#### page.setOfflineMode(enabled)
|
||||
- `enabled` <[boolean]> When `true`, enables offline mode for the page.
|
||||
- returns: <[Promise]>
|
||||
|
||||
#### page.setUserAgent(userAgent)
|
||||
- `userAgent` <[string]> Specific user agent to use in this page
|
||||
- returns: <[Promise]> Promise which resolves when the user agent is set.
|
||||
@ -3111,6 +3097,16 @@ await resultHandle.dispose();
|
||||
Aborts request. To use this, request interception should be enabled with `page.interception.enable()`.
|
||||
Exception is immediately thrown if the request interception is not enabled.
|
||||
|
||||
#### interception.authenticate(credentials)
|
||||
- `credentials` <?[Object]>
|
||||
- `username` <[string]>
|
||||
- `password` <[string]>
|
||||
- returns: <[Promise]>
|
||||
|
||||
Provide credentials for [HTTP authentication](https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication).
|
||||
|
||||
To disable authentication, pass `null`.
|
||||
|
||||
#### interception.continue(request, [overrides])
|
||||
- `request` <[Request]>
|
||||
- `overrides` <[Object]> Optional request overwrites, which can be one of the following:
|
||||
@ -3195,6 +3191,9 @@ page.on('request', request => {
|
||||
> **NOTE** Mocking responses for dataURL requests is not supported.
|
||||
> Calling `request.respond` for a dataURL request is a noop.
|
||||
|
||||
#### interception.setOfflineMode(enabled)
|
||||
- `enabled` <[boolean]> When `true`, enables offline mode for the page.
|
||||
- returns: <[Promise]>
|
||||
|
||||
### class: JSHandle
|
||||
|
||||
|
||||
@ -217,10 +217,6 @@ export class Page extends EventEmitter {
|
||||
return this._frameManager.frames();
|
||||
}
|
||||
|
||||
setOfflineMode(enabled: boolean) {
|
||||
return this._frameManager.networkManager().setOfflineMode(enabled);
|
||||
}
|
||||
|
||||
setDefaultNavigationTimeout(timeout: number) {
|
||||
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
|
||||
}
|
||||
@ -290,10 +286,6 @@ export class Page extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
async authenticate(credentials: { username: string; password: string; } | null) {
|
||||
return this._frameManager.networkManager().authenticate(credentials);
|
||||
}
|
||||
|
||||
async setExtraHTTPHeaders(headers: { [s: string]: string; }) {
|
||||
return this._frameManager.networkManager().setExtraHTTPHeaders(headers);
|
||||
}
|
||||
|
||||
@ -109,8 +109,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
||||
expect(coverage.length).toBe(0);
|
||||
});
|
||||
});
|
||||
// @see https://crbug.com/990945
|
||||
xit('should not hang when there is a debugger statement', async function({page, server}) {
|
||||
it('should not hang when there is a debugger statement', async function({page, server}) {
|
||||
await page.coverage.startJSCoverage();
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.evaluate(() => {
|
||||
|
||||
@ -92,6 +92,7 @@ class JSCoverage {
|
||||
helper.addEventListener(this._client, 'Debugger.scriptParsed', this._onScriptParsed.bind(this)),
|
||||
helper.addEventListener(this._client, 'Runtime.executionContextsCleared', this._onExecutionContextsCleared.bind(this)),
|
||||
];
|
||||
this._client.on('Debugger.paused', () => this._client.send('Debugger.resume'));
|
||||
await Promise.all([
|
||||
this._client.send('Profiler.enable'),
|
||||
this._client.send('Profiler.startPreciseCoverage', {callCount: false, detailed: true}),
|
||||
|
||||
@ -29,4 +29,12 @@ export class Interception {
|
||||
async abort(request: Request, errorCode: string = 'failed') {
|
||||
return request._abort(errorCode);
|
||||
}
|
||||
|
||||
setOfflineMode(enabled: boolean) {
|
||||
return this._networkManager.setOfflineMode(enabled);
|
||||
}
|
||||
|
||||
async authenticate(credentials: { username: string; password: string; } | null) {
|
||||
return this._networkManager.authenticate(credentials);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ module.exports.addTests = function({testRunner, expect, playwright, defaultBrows
|
||||
const page = await browser.newPage();
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
await page.interception.enable();
|
||||
page.on('request', r => r.respond({body: 'YO, GOOGLE.COM'}));
|
||||
page.on('request', r => page.interception.fulfill(r, {body: 'YO, GOOGLE.COM'}));
|
||||
await page.evaluate(() => {
|
||||
const frame = document.createElement('iframe');
|
||||
frame.setAttribute('src', 'https://google.com/');
|
||||
|
||||
@ -358,12 +358,12 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
||||
});
|
||||
|
||||
// FIXME: WebKit doesn't support network interception.
|
||||
describe.skip(FFOX || WEBKIT)('Page.authenticate', function() {
|
||||
describe.skip(FFOX || WEBKIT)('Interception.authenticate', function() {
|
||||
it('should work', async({page, server}) => {
|
||||
server.setAuth('/empty.html', 'user', 'pass');
|
||||
let response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.status()).toBe(401);
|
||||
await page.authenticate({
|
||||
await page.interception.authenticate({
|
||||
username: 'user',
|
||||
password: 'pass'
|
||||
});
|
||||
@ -373,7 +373,7 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
||||
it('should fail if wrong credentials', async({page, server}) => {
|
||||
// Use unique user/password since Chrome caches credentials per origin.
|
||||
server.setAuth('/empty.html', 'user2', 'pass2');
|
||||
await page.authenticate({
|
||||
await page.interception.authenticate({
|
||||
username: 'foo',
|
||||
password: 'bar'
|
||||
});
|
||||
@ -383,13 +383,13 @@ module.exports.addTests = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
||||
it('should allow disable authentication', async({page, server}) => {
|
||||
// Use unique user/password since Chrome caches credentials per origin.
|
||||
server.setAuth('/empty.html', 'user3', 'pass3');
|
||||
await page.authenticate({
|
||||
await page.interception.authenticate({
|
||||
username: 'user3',
|
||||
password: 'pass3'
|
||||
});
|
||||
let response = await page.goto(server.EMPTY_PAGE);
|
||||
expect(response.status()).toBe(200);
|
||||
await page.authenticate(null);
|
||||
await page.interception.authenticate(null);
|
||||
// Navigate to a different origin to bust Chrome's credential caching.
|
||||
response = await page.goto(server.CROSS_PROCESS_PREFIX + '/empty.html');
|
||||
expect(response.status()).toBe(401);
|
||||
|
||||
@ -166,21 +166,21 @@ module.exports.addTests = function({testRunner, expect, headless, playwright, FF
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip(FFOX || WEBKIT)('Page.setOfflineMode', function() {
|
||||
describe.skip(FFOX || WEBKIT)('Interception.setOfflineMode', function() {
|
||||
it('should work', async({page, server}) => {
|
||||
await page.setOfflineMode(true);
|
||||
await page.interception.setOfflineMode(true);
|
||||
let error = null;
|
||||
await page.goto(server.EMPTY_PAGE).catch(e => error = e);
|
||||
expect(error).toBeTruthy();
|
||||
await page.setOfflineMode(false);
|
||||
await page.interception.setOfflineMode(false);
|
||||
const response = await page.reload();
|
||||
expect(response.status()).toBe(200);
|
||||
});
|
||||
it('should emulate navigator.onLine', async({page, server}) => {
|
||||
expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);
|
||||
await page.setOfflineMode(true);
|
||||
await page.interception.setOfflineMode(true);
|
||||
expect(await page.evaluate(() => window.navigator.onLine)).toBe(false);
|
||||
await page.setOfflineMode(false);
|
||||
await page.interception.setOfflineMode(false);
|
||||
expect(await page.evaluate(() => window.navigator.onLine)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user