首页 > 解决方案 > 在 Chrome 88 更新后,top.window.close() 在 Google Editor 插件上停止工作

问题描述

我们正在使用为 google App-script Google-outhClient2提供的 Google Outh2 客户端来授权访问我们的服务器。该库在下一个选项卡中打开授权 URL,成功登录后,它将使用我们编写的自定义函数关闭选项卡

setTimeout(function() { top.window.close() }, 1);

但是,最近 Chrome 更新到 88 后,上述方法已经停止工作。这是我收到的消息

“脚本只能关闭它们打开的窗口”

当我阅读有关 Chrome 88 更改的信息时,我发现了 Google 对“Tab Hopping”的政策更改

关于如何解决这个问题的任何其他见解都会有所帮助。

在此处更新了代码工作流程

function getDriveService() {
try {
 return OAuth2.createService(‘service’)       
      .setAuthorizationBaseUrl(authUrl)
      .setTokenUrl(tokenUrl)
      .setRefreshUrl(tokenUrl)
      .setClientId(Client ID)
      .setClientSecret(Client Secret)
      .setCallbackFunction('authCallback')
      .setPropertyStore(PropertiesService.getUserProperties())
      .setScope('user')
      .setExpirationMinutes(0)
      .setParam('access_type', 'offline')
     .setParam('prompt', 'consent')
    } 
    catch(e) {
     
    }
}


function authCallback(request) {
  try {
  var driveService = getDriveService();
  var isAuthorized = driveService.handleCallback(request);
  if (isAuthorized) {
    showFile();
    return HtmlService.createHtmlOutput('Success! <script>setTimeout(function() { top.window.close() }, 1);</script>');
  } else {
    return HtmlService.createHtmlOutput('Denied. You can close this tab');
  }
} 
catch(e) {
}
}

标签: javascriptgoogle-chromegoogle-apps-scriptgoogle-sheetsdom-events

解决方案


推荐阅读