Google appscript 无法识别基于 Chromium 的 Edge

Google appscript does not recognize Chromium based Edge

我正在尝试在 google 幻灯片插件中检测基于 Chromium 的 Edge 浏览器。

Code.gs

function onInstall(event) {
    onOpen(event);
}

function onOpen(event) {
    SlidesApp.getUi().createAddonMenu()
        .addItem('Open the sidebar', '_showSidebar')
        .addToUi();
    _showSidebar();
}

function _showSidebar() {
    var ui = HtmlService
        .createHtmlOutputFromFile('index')
        .setTitle('Test add-on');
    SlidesApp.getUi().showSidebar(ui);
}

index.html

<html>
  <head>
    <base target="_top">
    
    <script>
       const onButtonClick = () => {
         console.log(window.navigator.userAgent);
       }
    </script>
  </head>
  <body>
    <button onclick="onButtonClick()">Click me</button>
  </body>
</html>

单击边栏中的按钮会记录到控制台:

5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36

但是当我手动输入 window.navigator.userAgent 到浏览器控制台时,日志看起来不同(缺少 Edg/84.0.522.49):

5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.49

主要问题是您的 Google 幻灯片 addon/sidebar 运行 位于 docs.google.com.

上托管的 iframe 中

新的基于 Chromium 的 Microsoft Edge 浏览器overrides User-Agent on some sites to maximize compatibility. If you open edge://compat/useragent in your Edge you will see that the docs.google.com is listed in that "User agent overrides" list:

要禁用用户代理覆盖功能,您可以 运行 Microsoft Edge 可执行文件使用以下命令行参数: --disable-domain-action-user-agent-override