mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
Previously we built DevTools for all browsers with version 2 of the manifest file format. This commit includes a number of refactors and API additions that will enable us to build DevTools with version 3 of the manifest file format. The manifest v3 build of Angular DevTools has been tested on Chrome, Edge, and Safari. Notably, the Firefox version of Angular DevTools remains as a manifest v2 build. Firefox does not yet support manifest v3 in it's latest stable release. When Firefox makes this transition, a follow up PR will update the Firefox manifest file to version 3. Because Firefox still needs v2, we need to keep some old v2 APIs around in our background page (service worker in v3) that will execute conditionally based on if the extension was built for v2 or v3. This is determined with the chrome.runtime.getManifest().manifest_version API. PR Close #47575
53 lines
1.5 KiB
TypeScript
53 lines
1.5 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.io/license
|
|
*/
|
|
|
|
export interface AngularDetection {
|
|
// This is necessary because the runtime
|
|
// message listener handles messages globally
|
|
// including from other extensions. We don't
|
|
// want to set icon and/or popup based on
|
|
// a message coming from an unrelated extension.
|
|
isAngularDevTools: true;
|
|
isIvy: boolean;
|
|
isAngular: boolean;
|
|
isDebugMode: boolean;
|
|
isSupportedAngularVersion: boolean;
|
|
}
|
|
|
|
function detectAngular(win: Window): void {
|
|
const isDebugMode = Boolean((win as any).ng);
|
|
const ngVersionElement = document.querySelector('[ng-version]');
|
|
let isSupportedAngularVersion = false;
|
|
let isAngular = false;
|
|
|
|
if (ngVersionElement) {
|
|
isAngular = true;
|
|
const attr = ngVersionElement.getAttribute('ng-version');
|
|
const major = attr ? parseInt(attr.split('.')[0], 10) : -1;
|
|
// In case of g3 apps we support major 0.
|
|
if (attr && (major >= 12 || major === 0)) {
|
|
isSupportedAngularVersion = true;
|
|
}
|
|
}
|
|
|
|
win.postMessage(
|
|
{
|
|
isIvy: typeof (ngVersionElement as any)?.__ngContext__ !== 'undefined',
|
|
isAngular,
|
|
isDebugMode,
|
|
isSupportedAngularVersion,
|
|
isAngularDevTools: true,
|
|
} as AngularDetection,
|
|
'*');
|
|
|
|
if (!isAngular) {
|
|
setTimeout(() => detectAngular(win), 1000);
|
|
}
|
|
}
|
|
|
|
detectAngular(window);
|