Skip to content

Commit

Permalink
Reverted some of the changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yury-s committed Mar 20, 2021
1 parent 1cd9756 commit c0c885d
Show file tree
Hide file tree
Showing 26 changed files with 110 additions and 124 deletions.
3 changes: 1 addition & 2 deletions src/browserServerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { BrowserContext, Video } from './server/browserContext';
import { StreamDispatcher } from './dispatchers/streamDispatcher';
import { ProtocolLogger } from './server/types';
import { CallMetadata, internalCallMetadata, SdkObject } from './server/instrumentation';
import { debugLogger } from './utils/debugLogger';

export class BrowserServerLauncherImpl implements BrowserServerLauncher {
private _browserType: BrowserType;
Expand Down Expand Up @@ -117,7 +116,7 @@ export class BrowserServerImpl extends EventEmitter implements BrowserServer {
socket.send(JSON.stringify(message));
};
socket.on('message', (message: string) => {
connection.dispatch(JSON.parse(Buffer.from(message).toString())).catch(e => debugLogger.log('error', e));
connection.dispatch(JSON.parse(Buffer.from(message).toString()));
});
socket.on('error', () => {});
const selectors = new Selectors();
Expand Down
4 changes: 2 additions & 2 deletions src/client/android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Android extends ChannelOwner<channels.AndroidChannel, channels.Andr

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(e => {});
this._channel.setDefaultTimeoutNoReply({ timeout });
}

async devices(): Promise<AndroidDevice[]> {
Expand Down Expand Up @@ -90,7 +90,7 @@ export class AndroidDevice extends ChannelOwner<channels.AndroidDeviceChannel, c

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(e => {});
this._channel.setDefaultTimeoutNoReply({ timeout });
}

serial(): string {
Expand Down
4 changes: 2 additions & 2 deletions src/client/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,

setDefaultNavigationTimeout(timeout: number) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
this._channel.setDefaultNavigationTimeoutNoReply({ timeout }).catch(e => {});
this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
}

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(e => {});
this._channel.setDefaultTimeoutNoReply({ timeout });
}

browser(): Browser | null {
Expand Down
12 changes: 6 additions & 6 deletions src/client/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia

setDefaultNavigationTimeout(timeout: number) {
this._timeoutSettings.setDefaultNavigationTimeout(timeout);
this._channel.setDefaultNavigationTimeoutNoReply({ timeout }).catch(e => {});
this._channel.setDefaultNavigationTimeoutNoReply({ timeout });
}

setDefaultTimeout(timeout: number) {
this._timeoutSettings.setDefaultTimeout(timeout);
this._channel.setDefaultTimeoutNoReply({ timeout }).catch(e => {});
this._channel.setDefaultTimeoutNoReply({ timeout });
}

video(): Video | null {
Expand Down Expand Up @@ -617,29 +617,29 @@ export class Page extends ChannelOwner<channels.PageChannel, channels.PageInitia

on(event: string | symbol, listener: Listener): this {
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: true }).catch(e => {});
this._channel.setFileChooserInterceptedNoReply({ intercepted: true });
super.on(event, listener);
return this;
}

addListener(event: string | symbol, listener: Listener): this {
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: true }).catch(e => {});
this._channel.setFileChooserInterceptedNoReply({ intercepted: true });
super.addListener(event, listener);
return this;
}

off(event: string | symbol, listener: Listener): this {
super.off(event, listener);
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: false }).catch(e => {});
this._channel.setFileChooserInterceptedNoReply({ intercepted: false });
return this;
}

removeListener(event: string | symbol, listener: Listener): this {
super.removeListener(event, listener);
if (event === Events.Page.FileChooser && !this.listenerCount(event))
this._channel.setFileChooserInterceptedNoReply({ intercepted: false }).catch(e => {});
this._channel.setFileChooserInterceptedNoReply({ intercepted: false });
return this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export abstract class Browser extends SdkObject {
const download = this._downloads.get(uuid);
if (!download)
return;
download._reportFinished(error).catch(e => {});
download._reportFinished(error);
this._downloads.delete(uuid);
}

Expand All @@ -100,13 +100,13 @@ export abstract class Browser extends SdkObject {
pageOrError.then(pageOrError => {
if (pageOrError instanceof Page)
pageOrError.videoStarted(video);
}, e => {});
});
}

_videoFinished(videoId: string) {
const video = this._idToVideo.get(videoId)!;
this._idToVideo.delete(videoId);
video._finish().catch(e => {});
video._finish();
}

_didClose() {
Expand Down
11 changes: 5 additions & 6 deletions src/server/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { readProtocolStream } from './crProtocolHelper';
import { Protocol } from './protocol';
import { CRExecutionContext } from './crExecutionContext';
import { CRDevTools } from './crDevTools';
import { debugLogger } from '../../utils/debugLogger';

export class CRBrowser extends Browser {
readonly _connection: CRConnection;
Expand Down Expand Up @@ -118,16 +117,16 @@ export class CRBrowser extends Browser {
}

if (targetInfo.type === 'other' && targetInfo.url.startsWith('devtools://devtools') && this._devtools) {
this._devtools.install(session).catch(e => debugLogger.log('error', e));
this._devtools.install(session);
return;
}

if (targetInfo.type === 'other' || !context) {
if (waitingForDebugger) {
// Ideally, detaching should resume any target, but there is a bug in the backend.
session.send('Runtime.runIfWaitingForDebugger').then(() => {
return this._session.send('Target.detachFromTarget', { sessionId });
}).catch(e => {});
session._sendMayFail('Runtime.runIfWaitingForDebugger').then(() => {
this._session._sendMayFail('Target.detachFromTarget', { sessionId });
});
}
return;
}
Expand All @@ -142,7 +141,7 @@ export class CRBrowser extends Browser {
backgroundPage.pageOrError().then(pageOrError => {
if (pageOrError instanceof Page)
context!.emit(CRBrowserContext.CREvents.BackgroundPage, backgroundPage._page);
}, e => {});
});
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/server/chromium/crConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class CRConnection extends EventEmitter {
for (const session of this._sessions.values())
session._onClosed(browserDisconnectedLogs);
this._sessions.clear();
void Promise.resolve().then(() => this.emit(ConnectionEvents.Disconnected));
Promise.resolve().then(() => this.emit(ConnectionEvents.Disconnected));
}

close() {
Expand Down Expand Up @@ -173,8 +173,8 @@ export class CRSession extends EventEmitter {
});
}

_sendNoReply<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): void {
this.send(method, params).catch((error: Error) => debugLogger.log('error', error));
_sendMayFail<T extends keyof Protocol.CommandParameters>(method: T, params?: Protocol.CommandParameters[T]): Promise<Protocol.CommandReturnValues[T] | void> {
return this.send(method, params).catch((error: Error) => debugLogger.log('error', error));
}

_onMessage(object: ProtocolResponse) {
Expand All @@ -187,7 +187,7 @@ export class CRSession extends EventEmitter {
callback.resolve(object.result);
} else {
assert(!object.id);
void Promise.resolve().then(() => {
Promise.resolve().then(() => {
if (this._eventListener)
this._eventListener(object.method!, object.params);
this.emit(object.method!, object.params);
Expand All @@ -211,7 +211,7 @@ export class CRSession extends EventEmitter {
callback.reject(rewriteErrorMessage(callback.error, `Protocol error (${callback.method}): ` + errorMessage));
this._callbacks.clear();
this._connection = null;
void Promise.resolve().then(() => this.emit(CRSessionEvents.Disconnected));
Promise.resolve().then(() => this.emit(CRSessionEvents.Disconnected));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/chromium/crCoverage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class JSCoverage {
}

_onDebuggerPaused() {
this._client.send('Debugger.resume').catch(() => {});
this._client.send('Debugger.resume');
}

_onExecutionContextsCleared() {
Expand All @@ -106,7 +106,7 @@ class JSCoverage {
if (!event.url && !this._reportAnonymousScripts)
return;
// This might fail if the page has already navigated away.
const response = await this._client.send('Debugger.getScriptSource', {scriptId: event.scriptId}).catch(e => null);
const response = await this._client._sendMayFail('Debugger.getScriptSource', {scriptId: event.scriptId});
if (response)
this._scriptSources.set(event.scriptId, response.scriptSource);
}
Expand Down Expand Up @@ -186,7 +186,7 @@ class CSSCoverage {
if (!header.sourceURL)
return;
// This might fail if the page has already navigated away.
const response = await this._client.send('CSS.getStyleSheetText', {styleSheetId: header.styleSheetId}).catch(e => null);
const response = await this._client._sendMayFail('CSS.getStyleSheetText', {styleSheetId: header.styleSheetId});
if (response) {
this._stylesheetURLs.set(header.styleSheetId, header.sourceURL);
this._stylesheetSources.set(header.styleSheetId, response.text);
Expand Down
4 changes: 2 additions & 2 deletions src/server/chromium/crDevTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class CRDevTools {
this._savePromise = Promise.resolve();
}

async install(session: CRSession) {
install(session: CRSession) {
session.on('Runtime.bindingCalled', async event => {
if (event.name !== kBindingName)
return;
Expand Down Expand Up @@ -66,7 +66,7 @@ export class CRDevTools {
contextId: event.executionContextId
}).catch(e => null);
});
await Promise.all([
Promise.all([
session.send('Runtime.enable'),
session.send('Runtime.addBinding', { name: kBindingName }),
session.send('Page.enable'),
Expand Down
24 changes: 12 additions & 12 deletions src/server/chromium/crNetworkManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,23 +152,23 @@ export class CRNetworkManager {
this._attemptedAuthentications.add(event.requestId);
}
const {username, password} = this._credentials || {username: undefined, password: undefined};
this._client._sendNoReply('Fetch.continueWithAuth', {
this._client._sendMayFail('Fetch.continueWithAuth', {
requestId: event.requestId,
authChallengeResponse: { response, username, password },
});
}

_onRequestPaused(workerFrame: frames.Frame | undefined, event: Protocol.Fetch.requestPausedPayload) {
if (!this._userRequestInterceptionEnabled && this._protocolRequestInterceptionEnabled) {
this._client._sendNoReply('Fetch.continueRequest', {
this._client._sendMayFail('Fetch.continueRequest', {
requestId: event.requestId
});
}
if (!event.networkId) {
// Fetch without networkId means that request was not recongnized by inspector, and
// it will never receive Network.requestWillBeSent. Most likely, this is an internal request
// that we can safely fail.
this._client._sendNoReply('Fetch.failRequest', {
this._client._sendMayFail('Fetch.failRequest', {
requestId: event.requestId,
errorReason: 'Aborted',
});
Expand Down Expand Up @@ -228,7 +228,7 @@ export class CRNetworkManager {
];
if (requestHeaders['Access-Control-Request-Headers'])
responseHeaders.push({ name: 'Access-Control-Allow-Headers', value: requestHeaders['Access-Control-Request-Headers'] });
this._client._sendNoReply('Fetch.fulfillRequest', {
this._client._sendMayFail('Fetch.fulfillRequest', {
requestId: requestPausedEvent.requestId,
responseCode: 204,
responsePhrase: network.STATUS_TEXTS['204'],
Expand All @@ -240,7 +240,7 @@ export class CRNetworkManager {

if (!frame) {
if (requestPausedEvent)
this._client._sendNoReply('Fetch.continueRequest', { requestId: requestPausedEvent.requestId });
this._client._sendMayFail('Fetch.continueRequest', { requestId: requestPausedEvent.requestId });
return;
}

Expand All @@ -249,7 +249,7 @@ export class CRNetworkManager {
allowInterception = false;
// We do not support intercepting redirects.
if (requestPausedEvent)
this._client._sendNoReply('Fetch.continueRequest', { requestId: requestPausedEvent.requestId });
this._client._sendMayFail('Fetch.continueRequest', { requestId: requestPausedEvent.requestId });
}
const isNavigationRequest = requestWillBeSentEvent.requestId === requestWillBeSentEvent.loaderId && requestWillBeSentEvent.type === 'Document';
const documentId = isNavigationRequest ? requestWillBeSentEvent.loaderId : undefined;
Expand Down Expand Up @@ -417,38 +417,38 @@ class InterceptableRequest implements network.RouteDelegate {
async continue(overrides: types.NormalizedContinueOverrides) {
// In certain cases, protocol will return error if the request was already canceled
// or the page was closed. We should tolerate these errors.
await this._client.send('Fetch.continueRequest', {
await this._client._sendMayFail('Fetch.continueRequest', {
requestId: this._interceptionId!,
url: overrides.url,
headers: overrides.headers,
method: overrides.method,
postData: overrides.postData ? overrides.postData.toString('base64') : undefined
}).catch(e => {});
});
}

async fulfill(response: types.NormalizedFulfillResponse) {
const body = response.isBase64 ? response.body : Buffer.from(response.body).toString('base64');

// In certain cases, protocol will return error if the request was already canceled
// or the page was closed. We should tolerate these errors.
await this._client.send('Fetch.fulfillRequest', {
await this._client._sendMayFail('Fetch.fulfillRequest', {
requestId: this._interceptionId!,
responseCode: response.status,
responsePhrase: network.STATUS_TEXTS[String(response.status)],
responseHeaders: response.headers,
body,
}).catch(e => {});
});
}

async abort(errorCode: string = 'failed') {
const errorReason = errorReasons[errorCode];
assert(errorReason, 'Unknown error code: ' + errorCode);
// In certain cases, protocol will return error if the request was already canceled
// or the page was closed. We should tolerate these errors.
await this._client.send('Fetch.failRequest', {
await this._client._sendMayFail('Fetch.failRequest', {
requestId: this._interceptionId!,
errorReason
}).catch(e => {});
});
}
}

Expand Down
Loading

0 comments on commit c0c885d

Please sign in to comment.