angular/devtools/projects/shell-browser/src/app/comm-utils.ts
Matthieu Riegler 302ea2ee46 fix(devtools): scope the message bus with URLs to prevent cross message interference
This prevents us from having detectAngular from running indefinitely.
2026-02-11 14:38:33 -08:00

38 lines
1.2 KiB
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
export function stripUrlQueryParamsAndFragment(url: string) {
const queryQuestionMarkIdx = url.indexOf('?');
if (queryQuestionMarkIdx > -1) {
url = url.substring(0, queryQuestionMarkIdx);
}
const fragmentHashIdx = url.indexOf('#');
if (fragmentHashIdx > -1) {
url = url.substring(0, fragmentHashIdx);
}
return url;
}
/** Returns the URI of the extension content script. */
export function getContentScriptUri() {
const url = stripUrlQueryParamsAndFragment(window.location.href);
return 'angular-devtools-content-script-' + url;
}
/** Returns the URI of the extension backend. */
export function getBackendUri() {
const url = stripUrlQueryParamsAndFragment(window.location.href);
return 'angular-devtools-backend-' + url;
}
/** Returns the URI of the Angular detection script. */
export function getDetectAngularScriptUri() {
const url = stripUrlQueryParamsAndFragment(window.location.href);
return 'angular-devtools-detect-angular-' + url;
}