How Chromium-Based Edge Enhancements Determine the Running Browser

Asked 2 years ago, Updated 2 years ago, 84 views

A Chromium-based version of Microsoft Edge was recently released.
This Edge can install extensions from the Chrome webstore.

So I installed my own extensions on Edge.
Redirecting to browser-specific pages does not work.

A browser-specific page is a page called chrome://newtab.
Edge://newtab appears to be a similar page.

So I would like to check the execution environment and change the redirect destination.
I don't know how to get it.

For Firefox Webextension and Chrome Extensions, use the following code to obtain the URL:
You can tell by the difference in the URL.

chrome.runtime.getURL("/");

However, Edge and Chrome will return the same value, so this is hard to tell.
There is also a way to check the User-Agent, which is not desirable because it cannot be retrieved until a request is made.

Is there any way to determine the browser?

When I tried again earlier, the redirect from the extension to chrome://newtab worked.
If you hit chrome://newtab on the edge, edge://newtab will replace it.
Also, when I hit about:newtab, edge://newtab was displayed.
Edge appears to be replacing chrome:// or about: with edge://

javascript chrome-extension firefox-webextension

2022-09-30 21:39

1 Answers

Currently, we have no choice but to use the User-Agent.

There is also a way to check the User-Agent, which is not desirable because it cannot be retrieved until a request is made.

navigator.userAgent can be retrieved without request.
(You can also retrieve it with content-script or background-script)

User-Agent Client Hints is recommended in the future.
You can also use the following functions to determine if you are supported:

function isEdge(){
    if(navigator.userAgentData){
        return navigator.userAgentData.brands.findIndex(item=>item.brand.includes("Edge"))!==-1;
    } else{
        return navigator.userAgent.indexOf("Edg")!==-1;
    }
}


2022-09-30 21:39

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.