2022-10-10 01:56:07 -04:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
2024-09-20 09:23:15 -06:00
|
|
|
* found in the LICENSE file at https://angular.dev/license
|
2022-10-10 01:56:07 -04:00
|
|
|
*/
|
|
|
|
|
|
2025-05-08 13:20:37 +00:00
|
|
|
import {AngularDetection} from '../../../protocol';
|
2023-08-30 12:10:53 +02:00
|
|
|
import {
|
|
|
|
|
appIsAngular,
|
|
|
|
|
appIsAngularInDevMode,
|
|
|
|
|
appIsAngularIvy,
|
|
|
|
|
appIsSupportedAngularVersion,
|
2025-05-08 13:20:37 +00:00
|
|
|
} from '../../../shared-utils';
|
2026-02-19 13:34:20 +01:00
|
|
|
import {getContentScriptUri, getDetectAngularScriptUri} from './comm-utils';
|
2023-08-30 12:10:53 +02:00
|
|
|
|
2024-03-04 22:54:58 -05:00
|
|
|
import {SamePageMessageBus} from './same-page-message-bus';
|
|
|
|
|
|
|
|
|
|
const detectAngularMessageBus = new SamePageMessageBus(
|
2026-03-06 00:32:20 +01:00
|
|
|
'[DetectAngular=>CS]',
|
2026-02-10 20:30:50 +01:00
|
|
|
getDetectAngularScriptUri(),
|
2026-02-19 13:34:20 +01:00
|
|
|
getContentScriptUri(),
|
2024-03-04 22:54:58 -05:00
|
|
|
);
|
2022-10-10 01:56:07 -04:00
|
|
|
|
2025-12-11 18:26:38 +02:00
|
|
|
let detectAngularTimeout: ReturnType<typeof setTimeout>;
|
2022-10-10 01:56:07 -04:00
|
|
|
function detectAngular(win: Window): void {
|
2023-08-30 12:10:53 +02:00
|
|
|
const isAngular = appIsAngular();
|
|
|
|
|
const isSupportedAngularVersion = appIsSupportedAngularVersion();
|
|
|
|
|
const isDebugMode = appIsAngularInDevMode();
|
|
|
|
|
const isIvy = appIsAngularIvy();
|
2022-10-10 01:56:07 -04:00
|
|
|
|
2024-03-04 22:54:58 -05:00
|
|
|
const detection: AngularDetection = {
|
|
|
|
|
isIvy,
|
|
|
|
|
isAngular,
|
|
|
|
|
isDebugMode,
|
|
|
|
|
isSupportedAngularVersion,
|
|
|
|
|
isAngularDevTools: true,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// For the background script to toggle the icon.
|
|
|
|
|
win.postMessage(detection, '*');
|
|
|
|
|
|
|
|
|
|
// For the content script to inject the backend.
|
|
|
|
|
detectAngularMessageBus.emit('detectAngular', [
|
2022-10-10 01:56:07 -04:00
|
|
|
{
|
2023-08-30 12:10:53 +02:00
|
|
|
isIvy,
|
2022-10-10 01:56:07 -04:00
|
|
|
isAngular,
|
|
|
|
|
isDebugMode,
|
|
|
|
|
isSupportedAngularVersion,
|
|
|
|
|
isAngularDevTools: true,
|
2024-03-04 22:54:58 -05:00
|
|
|
},
|
|
|
|
|
]);
|
2022-10-10 01:56:07 -04:00
|
|
|
|
2026-02-10 20:30:50 +01:00
|
|
|
detectAngularTimeout = setTimeout(() => {
|
|
|
|
|
detectAngular(win);
|
|
|
|
|
}, 1000);
|
2022-10-10 01:56:07 -04:00
|
|
|
}
|
|
|
|
|
|
2026-02-10 20:30:50 +01:00
|
|
|
detectAngularMessageBus.on('backendInstalled', (detection) => {
|
2025-12-11 18:26:38 +02:00
|
|
|
clearTimeout(detectAngularTimeout);
|
|
|
|
|
});
|
|
|
|
|
|
2022-10-10 01:56:07 -04:00
|
|
|
detectAngular(window);
|