@@ -6,7 +6,7 @@ import * as os from 'os';
66import * as fs from 'fs' ;
77import * 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' ;
1010import { spawn , ChildProcess , fork , execSync } from 'child_process' ;
1111import { Crdp } from 'vscode-chrome-debug-core' ;
1212import { DebugProtocol } from 'vscode-debugprotocol' ;
@@ -17,6 +17,7 @@ import * as errors from './errors';
1717
1818import * as nls from 'vscode-nls' ;
1919import { FinishedStartingUpEventArguments } from 'vscode-chrome-debug-core/lib/src/executionTimingsReporter' ;
20+ import { version } from 'vscode' ;
2021let localize = nls . loadMessageBundle ( ) ;
2122
2223// Keep in sync with sourceMapPathOverrides package.json default
@@ -216,7 +217,7 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
216217 }
217218
218219 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 ( ( ) => {
220+ return super . doAttach ( port , targetUrl , address , timeout , websocketUrl , extraCRDPChannelPort ) . then ( async ( ) => {
220221 // Don't return this promise, a failure shouldn't fail attach
221222 this . globalEvaluate ( { expression : 'navigator.userAgent' , silent : true } )
222223 . then (
@@ -278,6 +279,25 @@ export class ChromeDebugAdapter extends CoreDebugAdapter {
278279 */
279280 versionInformationPromise . then ( versionInformation => telemetry . telemetry . reportEvent ( 'target-version' , versionInformation ) ) ;
280281
282+ try {
283+ if ( this . _breakOnLoadHelper ) {
284+ // This is what -core is doing. We only actually care to see if this fails, to see if we need to apply the workaround
285+ const browserVersion = ( await this . _chromeConnection . version ) . browser ;
286+ if ( browserVersion . isAtLeastVersion ( 0 , 1 ) ) { // If this is false it means it's unknown version
287+ this . _breakOnLoadHelper . setBrowserVersion ( browserVersion ) ;
288+ } else {
289+ logger . log ( `/json/version failed, attempting workaround to get the version` ) ;
290+ // If the original way failed, we try to use versionInformationPromise to get this information
291+ const versionInformation = await versionInformationPromise ;
292+ const browserVersion = Version . parse ( versionInformation [ 'Versions.Target.Version' ] ) ;
293+ this . _breakOnLoadHelper . setBrowserVersion ( browserVersion ) ;
294+ }
295+ }
296+ } catch ( exception ) {
297+ // If something fails we report telemetry and we ignore it
298+ telemetry . telemetry . reportEvent ( 'break-on-load-target-version-workaround-failed' , exception ) ;
299+ }
300+
281301 /* __GDPR__FRAGMENT__
282302 "DebugCommonProperties" : {
283303 "${include}": [ "${VersionInformation}" ]
0 commit comments