Skip to content

Commit 639615d

Browse files
committed
fix(chrome): new debug url with latest chrome 83+ versions
closes NativeScript/NativeScript#8605
1 parent 4c005ca commit 639615d

8 files changed

+71
-47
lines changed

lib/controllers/debug-controller.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ export class DebugController extends EventEmitter implements IDebugController {
157157
this.emit(DEBUGGER_ATTACHED_EVENT_NAME, debugInformation);
158158
}
159159

160-
this.$logger.info(`To start debugging, open the following URL in Chrome:${EOL}${debugInformation.url}${EOL}`.cyan);
160+
this.$logger.info(`To start debugging, open the following URL in Chrome:${EOL}${debugInformation.url}${EOL}`.green);
161+
162+
this.$logger.info(`If you're using an older Chrome version 82 and below, use this instead:${EOL}${debugInformation.legacyUrl}${EOL}`.cyan);
161163
}
162164

163165
return debugInformation;

lib/declarations.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ interface IGenerateOptions {
494494

495495
interface IDebugInformation extends IPort, Mobile.IDeviceIdentifier {
496496
url: string;
497+
legacyUrl?: string;
497498
}
498499

499500
interface IPort {

lib/definitions/debug.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface IDeviceDebugService extends IPlatform, NodeJS.EventEmitter {
116116

117117
interface IDebugResultInfo {
118118
debugUrl: string;
119+
legacyDebugUrl?: string;
119120
}
120121

121122
interface IAppDebugData extends IProjectDir {

lib/services/android-device-debug-service.ts

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class AndroidDeviceDebugService extends DebugServiceBase implements IDevi
9999
await this.printDebugPort(this.deviceIdentifier, debugPort);
100100

101101
result.debugUrl = this.getChromeDebugUrl(debugOptions, debugPort);
102+
result.legacyDebugUrl = this.getChromeDebugUrl(debugOptions, debugPort, true);
102103

103104
return result;
104105
}

lib/services/debug-service-base.ts

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ export abstract class DebugServiceBase extends EventEmitter implements IDeviceDe
2828
return true;
2929
}
3030
};
31-
}
31+
}
3232

33-
protected getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string {
33+
protected getChromeDebugUrl(debugOptions: IDebugOptions, port: number, legacy?: boolean): string {
3434
// corresponds to 55.0.2883 Chrome version
3535
// SHA is taken from https://chromium.googlesource.com/chromium/src/+/55.0.2883.100
3636
// This SHA is old and does not support debugging with HMR.
@@ -39,17 +39,19 @@ export abstract class DebugServiceBase extends EventEmitter implements IDeviceDe
3939
// Using the actual commit will result in 404 error in the remote serve.
4040
const commitSHA = debugOptions.devToolsCommit || "02e6bde1bbe34e43b309d4ef774b1168d25fd024";
4141

42-
let chromeDevToolsPrefix = `chrome-devtools://devtools/remote/serve_file/@${commitSHA}`;
42+
const devToolsProtocol = `${legacy ? 'chrome-' : ''}devtools`;
43+
44+
let chromeDevToolsPrefix = `${devToolsProtocol}://devtools/remote/serve_file/@${commitSHA}`;
4345

4446
if (debugOptions.useBundledDevTools === undefined || debugOptions.useBundledDevTools) {
45-
chromeDevToolsPrefix = "chrome-devtools://devtools/bundled";
47+
chromeDevToolsPrefix = `${devToolsProtocol}://devtools/bundled`;
4648
}
4749

4850
if (debugOptions.useHttpUrl) {
4951
chromeDevToolsPrefix = `https://chrome-devtools-frontend.appspot.com/serve_file/@${commitSHA}`;
5052
}
5153

52-
const chromeUrl = `${chromeDevToolsPrefix}/inspector.html?experiments=true&ws=localhost:${port}`;
54+
const chromeUrl = `${chromeDevToolsPrefix}/inspector.html?ws=localhost:${port}${legacy ? '&experiments=true' : ''}`;
5355
return chromeUrl;
5456
}
5557
}

lib/services/ios-device-debug-service.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,9 @@ export class IOSDeviceDebugService extends DebugServiceBase implements IDeviceDe
3232

3333
@performanceLog()
3434
public async debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugResultInfo> {
35-
const result: IDebugResultInfo = { debugUrl: null };
3635
await this.validateOptions(debugOptions);
3736

38-
result.debugUrl = await this.wireDebuggerClient(debugData, debugOptions);
39-
40-
return result;
37+
return await this.wireDebuggerClient(debugData, debugOptions);
4138
}
4239

4340
public async debugStop(): Promise<void> {
@@ -84,25 +81,28 @@ export class IOSDeviceDebugService extends DebugServiceBase implements IDeviceDe
8481
}
8582

8683
@performanceLog()
87-
private async wireDebuggerClient(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
84+
private async wireDebuggerClient(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugResultInfo> {
8885
if ((debugOptions.inspector || !debugOptions.client) && this.$hostInfo.isDarwin) {
8986
return await this.setupTcpAppDebugProxy(debugData, debugOptions);
9087
} else {
9188
return await this.setupWebAppDebugProxy(debugOptions, debugData);
9289
}
9390
}
9491

95-
private async setupWebAppDebugProxy(debugOptions: IDebugOptions, debugData: IDebugData): Promise<string> {
92+
private async setupWebAppDebugProxy(debugOptions: IDebugOptions, debugData: IDebugData): Promise<IDebugResultInfo> {
9693
if (debugOptions.chrome) {
9794
this.$logger.info("'--chrome' is the default behavior. Use --inspector to debug iOS applications using the Safari Web Inspector.");
9895
}
9996
const projectName = this.getProjectName(debugData);
10097
const webSocketProxy = await this.$appDebugSocketProxyFactory.ensureWebSocketProxy(this.device, debugData.applicationIdentifier, projectName, debugData.projectDir);
10198

102-
return this.getChromeDebugUrl(debugOptions, webSocketProxy.options.port);
99+
return {
100+
debugUrl: this.getChromeDebugUrl(debugOptions, webSocketProxy.options.port),
101+
legacyDebugUrl: this.getChromeDebugUrl(debugOptions, webSocketProxy.options.port, true)
102+
};
103103
}
104104

105-
private async setupTcpAppDebugProxy(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
105+
private async setupTcpAppDebugProxy(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugResultInfo> {
106106
const projectName = this.getProjectName(debugData);
107107
const existingTcpProxy = this.$appDebugSocketProxyFactory.getTCPSocketProxy(this.deviceIdentifier, debugData.applicationIdentifier);
108108
const tcpSocketProxy = existingTcpProxy || await this.$appDebugSocketProxyFactory.addTCPSocketProxy(this.device, debugData.applicationIdentifier, projectName, debugData.projectDir);

test/services/android-device-debug-service.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class AndroidDeviceDebugServiceInheritor extends AndroidDeviceDebugService {
1717
super(<any>{ deviceInfo: { identifier: "123" } }, $devicesService, $cleanupService, $errors, $logger, $androidProcessService, $staticConfig, $net, $deviceLogProvider);
1818
}
1919

20-
public getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string {
21-
return super.getChromeDebugUrl(debugOptions, port);
20+
public getChromeDebugUrl(debugOptions: IDebugOptions, port: number, legacy?: boolean): string {
21+
return super.getChromeDebugUrl(debugOptions, port, legacy);
2222
}
2323
}
2424

@@ -43,6 +43,7 @@ interface IChromeUrlTestCase {
4343
debugOptions: IDebugOptions;
4444
expectedChromeUrl: string;
4545
scenarioName: string;
46+
legacy?: boolean;
4647
}
4748

4849
describe("androidDeviceDebugService", () => {
@@ -55,7 +56,14 @@ describe("androidDeviceDebugService", () => {
5556
{
5657
scenarioName: "useBundledDevTools and useHttpUrl are not passed",
5758
debugOptions: {},
58-
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
59+
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
60+
},
61+
// legacy chrome debug url
62+
{
63+
scenarioName: "useBundledDevTools and useHttpUrl are not passed and using legacy chrome debug url",
64+
debugOptions: {},
65+
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}&experiments=true`,
66+
legacy: true
5967
},
6068

6169
// When useBundledDevTools is true
@@ -64,23 +72,23 @@ describe("androidDeviceDebugService", () => {
6472
debugOptions: {
6573
useBundledDevTools: true
6674
},
67-
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
75+
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
6876
},
6977
{
7078
scenarioName: "useBundledDevTools is true and useHttpUrl is false",
7179
debugOptions: {
7280
useBundledDevTools: true,
7381
useHttpUrl: false
7482
},
75-
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
83+
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
7684
},
7785
{
7886
scenarioName: "useBundledDevTools is true and useHttpUrl is true",
7987
debugOptions: {
8088
useBundledDevTools: true,
8189
useHttpUrl: true
8290
},
83-
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
91+
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
8492
},
8593

8694
// When useBundledDevTools is false
@@ -89,23 +97,23 @@ describe("androidDeviceDebugService", () => {
8997
debugOptions: {
9098
useBundledDevTools: false
9199
},
92-
expectedChromeUrl: `chrome-devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
100+
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
93101
},
94102
{
95103
scenarioName: "useBundledDevTools is false and useHttpUrl is false",
96104
debugOptions: {
97105
useBundledDevTools: false,
98106
useHttpUrl: false
99107
},
100-
expectedChromeUrl: `chrome-devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
108+
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
101109
},
102110
{
103111
scenarioName: "useBundledDevTools is false and useHttpUrl is true",
104112
debugOptions: {
105113
useBundledDevTools: false,
106114
useHttpUrl: true
107115
},
108-
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
116+
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
109117
},
110118

111119
// When useBundledDevTools is not passed
@@ -114,14 +122,14 @@ describe("androidDeviceDebugService", () => {
114122
debugOptions: {
115123
useHttpUrl: false
116124
},
117-
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
125+
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
118126
},
119127
{
120128
scenarioName: "useBundledDevTools is not passed and useHttpUrl is true",
121129
debugOptions: {
122130
useHttpUrl: true
123131
},
124-
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
132+
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
125133
},
126134

127135
// devToolsCommit tests
@@ -130,36 +138,36 @@ describe("androidDeviceDebugService", () => {
130138
debugOptions: {
131139
useBundledDevTools: false
132140
},
133-
expectedChromeUrl: `chrome-devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
141+
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${expectedDevToolsCommitSha}/inspector.html?ws=localhost:${expectedPort}`,
134142
},
135143
{
136144
scenarioName: "devToolsCommit is disregarded when useBundledDevTools is not passed",
137145
debugOptions: {},
138-
expectedChromeUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
146+
expectedChromeUrl: `devtools://devtools/bundled/inspector.html?ws=localhost:${expectedPort}`,
139147
},
140148
{
141149
scenarioName: "devToolsCommit is set to passed value when useBundledDevTools is set to false",
142150
debugOptions: {
143151
useBundledDevTools: false,
144152
devToolsCommit: customDevToolsCommit
145153
},
146-
expectedChromeUrl: `chrome-devtools://devtools/remote/serve_file/@${customDevToolsCommit}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
154+
expectedChromeUrl: `devtools://devtools/remote/serve_file/@${customDevToolsCommit}/inspector.html?ws=localhost:${expectedPort}`,
147155
},
148156
{
149157
scenarioName: "devToolsCommit is set to passed value when useHttpUrl is set to true",
150158
debugOptions: {
151159
useHttpUrl: true,
152160
devToolsCommit: customDevToolsCommit
153161
},
154-
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${customDevToolsCommit}/inspector.html?experiments=true&ws=localhost:${expectedPort}`,
162+
expectedChromeUrl: `https://chrome-devtools-frontend.appspot.com/serve_file/@${customDevToolsCommit}/inspector.html?ws=localhost:${expectedPort}`,
155163
}
156164
];
157165

158166
for (const testCase of chromUrlTestCases) {
159167
it(`returns correct url when ${testCase.scenarioName}`, () => {
160168
const testInjector = createTestInjector();
161169
const androidDeviceDebugService = testInjector.resolve<AndroidDeviceDebugServiceInheritor>(AndroidDeviceDebugServiceInheritor);
162-
const actualChromeUrl = androidDeviceDebugService.getChromeDebugUrl(testCase.debugOptions, expectedPort);
170+
const actualChromeUrl = androidDeviceDebugService.getChromeDebugUrl(testCase.debugOptions, expectedPort, testCase.legacy);
163171
assert.equal(actualChromeUrl, testCase.expectedChromeUrl);
164172
});
165173
}

0 commit comments

Comments
 (0)