Skip to content
This repository was archived by the owner on Dec 6, 2022. It is now read-only.

Commit be6219f

Browse files
authored
Merge pull request #731 from digeff/workaround_for_json_version_failing
Workaround for json/version failing
2 parents 0a3a271 + ffbfd5b commit be6219f

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

src/chromeDebugAdapter.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import * as os from 'os';
66
import * as fs from 'fs';
77
import * as path from 'path';
88

9-
import {ChromeDebugAdapter as CoreDebugAdapter, logger, utils as coreUtils, ISourceMapPathOverrides, ChromeDebugSession, telemetry, ITelemetryPropertyCollector, IOnPausedResult } from 'vscode-chrome-debug-core';
9+
import {ChromeDebugAdapter as CoreDebugAdapter, logger, utils as coreUtils, ISourceMapPathOverrides, ChromeDebugSession, telemetry, ITelemetryPropertyCollector, IOnPausedResult, Version } from 'vscode-chrome-debug-core';
1010
import { spawn, ChildProcess, fork, execSync } from 'child_process';
1111
import { Crdp } from 'vscode-chrome-debug-core';
1212
import { DebugProtocol } from 'vscode-debugprotocol';
@@ -216,7 +216,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
216216
}
217217

218218
protected doAttach(port: number, targetUrl?: string, address?: string, timeout?: number, websocketUrl?: string, extraCRDPChannelPort?: number): Promise<void> {
219-
return super.doAttach(port, targetUrl, address, timeout, websocketUrl, extraCRDPChannelPort).then(() => {
219+
return super.doAttach(port, targetUrl, address, timeout, websocketUrl, extraCRDPChannelPort).then(async () => {
220220
// Don't return this promise, a failure shouldn't fail attach
221221
this.globalEvaluate({ expression: 'navigator.userAgent', silent: true })
222222
.then(
@@ -278,6 +278,23 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
278278
*/
279279
versionInformationPromise.then(versionInformation => telemetry.telemetry.reportEvent('target-version', versionInformation));
280280

281+
try {
282+
if (this._breakOnLoadHelper) {
283+
// This is what -core is doing. We only actually care to see if this fails, to see if we need to apply the workaround
284+
const browserVersion = (await this._chromeConnection.version).browser;
285+
if (!browserVersion.isAtLeastVersion(0, 1)) { // If this is true it means it's unknown version
286+
logger.log(`/json/version failed, attempting workaround to get the version`);
287+
// If the original way failed, we try to use versionInformationPromise to get this information
288+
const versionInformation = await versionInformationPromise;
289+
const alternativeBrowserVersion = Version.parse(versionInformation['Versions.Target.Version']);
290+
this._breakOnLoadHelper.setBrowserVersion(alternativeBrowserVersion);
291+
}
292+
}
293+
} catch (exception) {
294+
// If something fails we report telemetry and we ignore it
295+
telemetry.telemetry.reportEvent('break-on-load-target-version-workaround-failed', exception);
296+
}
297+
281298
/* __GDPR__FRAGMENT__
282299
"DebugCommonProperties" : {
283300
"${include}": [ "${VersionInformation}" ]

0 commit comments

Comments
 (0)