fix(Network): response.ok should be true for file:// urls (#2152)
This commit is contained in:
parent
cad71d9bd9
commit
826fe42c48
@ -537,7 +537,7 @@ class Response {
|
|||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
ok() {
|
ok() {
|
||||||
return this._status >= 200 && this._status <= 299;
|
return this._status === 0 || (this._status >= 200 && this._status <= 299);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -772,4 +772,4 @@ const statusTexts = {
|
|||||||
'511': 'Network Authentication Required',
|
'511': 'Network Authentication Required',
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = NetworkManager;
|
module.exports = {Request, Response, NetworkManager};
|
||||||
|
15
lib/Page.js
15
lib/Page.js
@ -17,7 +17,7 @@
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const mime = require('mime');
|
const mime = require('mime');
|
||||||
const NetworkManager = require('./NetworkManager');
|
const {NetworkManager} = require('./NetworkManager');
|
||||||
const NavigatorWatcher = require('./NavigatorWatcher');
|
const NavigatorWatcher = require('./NavigatorWatcher');
|
||||||
const Dialog = require('./Dialog');
|
const Dialog = require('./Dialog');
|
||||||
const EmulationManager = require('./EmulationManager');
|
const EmulationManager = require('./EmulationManager');
|
||||||
@ -478,11 +478,12 @@ class Page extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* @param {string} url
|
* @param {string} url
|
||||||
* @param {!Object=} options
|
* @param {!Object=} options
|
||||||
* @return {!Promise<?Response>}
|
* @return {!Promise<?Puppeteer.Response>}
|
||||||
*/
|
*/
|
||||||
async goto(url, options = {}) {
|
async goto(url, options = {}) {
|
||||||
const referrer = this._networkManager.extraHTTPHeaders()['referer'];
|
const referrer = this._networkManager.extraHTTPHeaders()['referer'];
|
||||||
|
|
||||||
|
/** @type {Map<string, !Puppeteer.Request>} */
|
||||||
const requests = new Map();
|
const requests = new Map();
|
||||||
const eventListeners = [
|
const eventListeners = [
|
||||||
helper.addEventListener(this._networkManager, NetworkManager.Events.Request, request => {
|
helper.addEventListener(this._networkManager, NetworkManager.Events.Request, request => {
|
||||||
@ -526,7 +527,7 @@ class Page extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object=} options
|
* @param {!Object=} options
|
||||||
* @return {!Promise<?Response>}
|
* @return {!Promise<?Puppeteer.Response>}
|
||||||
*/
|
*/
|
||||||
async reload(options) {
|
async reload(options) {
|
||||||
const [response] = await Promise.all([
|
const [response] = await Promise.all([
|
||||||
@ -538,7 +539,7 @@ class Page extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object=} options
|
* @param {!Object=} options
|
||||||
* @return {!Promise<!Response>}
|
* @return {!Promise<!Puppeteer.Response>}
|
||||||
*/
|
*/
|
||||||
async waitForNavigation(options = {}) {
|
async waitForNavigation(options = {}) {
|
||||||
const mainFrame = this._frameManager.mainFrame();
|
const mainFrame = this._frameManager.mainFrame();
|
||||||
@ -556,7 +557,7 @@ class Page extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object=} options
|
* @param {!Object=} options
|
||||||
* @return {!Promise<?Response>}
|
* @return {!Promise<?Puppeteer.Response>}
|
||||||
*/
|
*/
|
||||||
async goBack(options) {
|
async goBack(options) {
|
||||||
return this._go(-1, options);
|
return this._go(-1, options);
|
||||||
@ -564,7 +565,7 @@ class Page extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object=} options
|
* @param {!Object=} options
|
||||||
* @return {!Promise<?Response>}
|
* @return {!Promise<?Puppeteer.Response>}
|
||||||
*/
|
*/
|
||||||
async goForward(options) {
|
async goForward(options) {
|
||||||
return this._go(+1, options);
|
return this._go(+1, options);
|
||||||
@ -572,7 +573,7 @@ class Page extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {!Object=} options
|
* @param {!Object=} options
|
||||||
* @return {!Promise<?Response>}
|
* @return {!Promise<?Puppeteer.Response>}
|
||||||
*/
|
*/
|
||||||
async _go(delta, options) {
|
async _go(delta, options) {
|
||||||
const history = await this._client.send('Page.getNavigationHistory');
|
const history = await this._client.send('Page.getNavigationHistory');
|
||||||
|
6
lib/externs.d.ts
vendored
6
lib/externs.d.ts
vendored
@ -7,7 +7,7 @@ import {Mouse as RealMouse, Keyboard as RealKeyboard, Touchscreen as RealTouchsc
|
|||||||
import {Frame as RealFrame, FrameManager as RealFrameManager} from './FrameManager.js';
|
import {Frame as RealFrame, FrameManager as RealFrameManager} from './FrameManager.js';
|
||||||
import {JSHandle as RealJSHandle, ExecutionContext as RealExecutionContext} from './ExecutionContext.js';
|
import {JSHandle as RealJSHandle, ExecutionContext as RealExecutionContext} from './ExecutionContext.js';
|
||||||
import * as RealElementHandle from './ElementHandle.js';
|
import * as RealElementHandle from './ElementHandle.js';
|
||||||
import * as RealNetworkManager from './NetworkManager.js';
|
import { NetworkManager as RealNetworkManager, Request as RealRequest, Response as RealResponse } from './NetworkManager.js';
|
||||||
import * as child_process from 'child_process';
|
import * as child_process from 'child_process';
|
||||||
export as namespace Puppeteer;
|
export as namespace Puppeteer;
|
||||||
|
|
||||||
@ -25,7 +25,9 @@ export class NetworkManager extends RealNetworkManager {}
|
|||||||
export class ElementHandle extends RealElementHandle {}
|
export class ElementHandle extends RealElementHandle {}
|
||||||
export class JSHandle extends RealJSHandle {}
|
export class JSHandle extends RealJSHandle {}
|
||||||
export class ExecutionContext extends RealExecutionContext {}
|
export class ExecutionContext extends RealExecutionContext {}
|
||||||
export class Page extends RealPage {}
|
export class Page extends RealPage { }
|
||||||
|
export class Response extends RealResponse { }
|
||||||
|
export class Request extends RealRequest { }
|
||||||
|
|
||||||
export interface ConnectionTransport extends NodeJS.EventEmitter {
|
export interface ConnectionTransport extends NodeJS.EventEmitter {
|
||||||
send(string);
|
send(string);
|
||||||
|
Loading…
Reference in New Issue
Block a user