/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
devtools/projects/shell-browser/src/app/detect-angular.ts
64 строки
2 KB
Matthieu Riegler
refactor(devtools): prevent spamming the message bus
09 мар 2026, 20:45
09 мар 2026, 20:45
263b819
Код
Авторство
О чём код?
/** * @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 */ import {AngularDetection} from '../../../protocol'; import { appIsAngular, appIsAngularInDevMode, appIsAngularIvy, appIsSupportedAngularVersion, } from '../../../shared-utils'; import {getContentScriptUri, getDetectAngularScriptUri} from './comm-utils'; import {SamePageMessageBus} from './same-page-message-bus'; const detectAngularMessageBus = new SamePageMessageBus( '[DetectAngular=>CS]', getDetectAngularScriptUri(), getContentScriptUri(), ); let detectAngularTimeout: ReturnType<typeof setTimeout>; function detectAngular(win: Window): void { const isAngular = appIsAngular(); const isSupportedAngularVersion = appIsSupportedAngularVersion(); const isDebugMode = appIsAngularInDevMode(); const isIvy = appIsAngularIvy(); 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', [ { isIvy, isAngular, isDebugMode, isSupportedAngularVersion, isAngularDevTools: true, }, ]); detectAngularTimeout = setTimeout(() => { detectAngular(win); }, 1000); } detectAngularMessageBus.on('backendInstalled', (detection) => { clearTimeout(detectAngularTimeout); }); detectAngular(window);