2021-12-09 21:37:01 -05: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
|
2021-12-09 21:37:01 -05:00
|
|
|
*/
|
|
|
|
|
|
2025-05-08 13:20:37 +00:00
|
|
|
import {initializeMessageBus} from '../../../ng-devtools-backend';
|
2020-02-07 16:09:36 -05:00
|
|
|
|
2026-06-30 16:39:22 +03:00
|
|
|
import {removeHighlightsByType} from '../../../ng-devtools-backend/src/lib/shared/highlighter';
|
|
|
|
|
import {HighlightType} from '../../../ng-devtools-backend/src/lib/shared/highlighter/highlights';
|
2021-12-09 00:44:17 -05:00
|
|
|
|
|
|
|
|
import {initializeExtendedWindowOperations} from './chrome-window-extensions';
|
2026-02-10 20:30:50 +01:00
|
|
|
import {getBackendUri, getContentScriptUri} from './comm-utils';
|
2021-12-09 00:44:17 -05:00
|
|
|
import {SamePageMessageBus} from './same-page-message-bus';
|
|
|
|
|
|
2026-03-06 00:32:20 +01:00
|
|
|
const messageBus = new SamePageMessageBus(
|
|
|
|
|
'[Backend=>ContentScript]',
|
|
|
|
|
getBackendUri(),
|
|
|
|
|
getContentScriptUri(),
|
|
|
|
|
);
|
2020-01-27 13:40:18 -05:00
|
|
|
|
|
|
|
|
let initialized = false;
|
|
|
|
|
messageBus.on('handshake', () => {
|
|
|
|
|
if (initialized) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
initialized = true;
|
2020-02-07 16:09:36 -05:00
|
|
|
initializeMessageBus(messageBus);
|
|
|
|
|
initializeExtendedWindowOperations();
|
2020-04-14 18:27:59 -04:00
|
|
|
|
|
|
|
|
let inspectorRunning = false;
|
|
|
|
|
messageBus.on('inspectorStart', () => {
|
|
|
|
|
inspectorRunning = true;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
messageBus.on('inspectorEnd', () => {
|
|
|
|
|
inspectorRunning = false;
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-09 00:44:17 -05:00
|
|
|
// handles case when mouse leaves chrome extension too quickly. unHighlight() is not a very
|
|
|
|
|
// expensive function and has an if check so it's DOM api call is not called more than necessary
|
|
|
|
|
document.addEventListener(
|
|
|
|
|
'mousemove',
|
|
|
|
|
() => {
|
|
|
|
|
if (!inspectorRunning) {
|
2026-07-15 21:59:04 +03:00
|
|
|
removeHighlightsByType(HighlightType.InspectElement);
|
2021-12-09 00:44:17 -05:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
false,
|
|
|
|
|
);
|
2024-03-04 22:54:58 -05:00
|
|
|
|
|
|
|
|
messageBus.emit('backendReady');
|
2020-01-27 13:40:18 -05:00
|
|
|
});
|