You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gmail插件中Google Apps Script无法打开非谷歌URL求助

Gmail Add-on 打开非谷歌URL问题解决

问题原因

Gmail Add-on的CardService.OpenAs.OVERLAY(弹窗模式)存在安全限制,仅允许打开谷歌官方域名链接或已通过OAuth授权的内部服务链接,直接打开非谷歌域名会触发平台类型错误。

解决思路

方案1:改用新标签页打开(无域名限制)

将setOpenAs的参数改为CardService.OpenAs.FULL_SIZE_TAB,这种模式会在浏览器新标签页打开任意外部URL,不受域名限制。

修改后的代码:

function buildAddOn(e) {
  var card = CardService.newCardBuilder();
  var section = CardService.newCardSection();
  var action = CardService.newAction().setFunctionName('openNewPopup');
  var button = CardService.newTextButton().setText('Click to open').setOnClickAction(action);
  section.addWidget(button);
  card.addSection(section);
  return card.build();
}

function openNewPopup(e) {
  // 改用新标签页模式打开外部链接
  var link = CardService.newOpenLink()
    .setUrl("https://www.facebook.com")
    .setOpenAs(CardService.OpenAs.FULL_SIZE_TAB);
  var actionResponse = CardService.newActionResponseBuilder().setOpenLink(link).build();
  return actionResponse;
}

方案2:通过Web App中间层实现弹窗打开(保留OVERLAY模式)

如果需要在弹窗中打开外部链接,可以创建一个Google Apps Script Web App,用iframe嵌入目标外部网站,然后在Add-on中打开这个Web App的链接:

  1. 创建新的Apps Script项目,编写Web App代码:
function doGet() {
  var html = HtmlService.createHtmlOutput('<iframe src="https://www.facebook.com" width="100%" height="100%" frameborder="0"></iframe>')
    .setSandboxMode(HtmlService.SandboxMode.IFRAME);
  return html;
}
  1. 部署该项目为Web App,设置权限为“任何人,甚至匿名”(可根据需求调整),复制生成的Web App URL。
  2. 在Add-on的setUrl中使用这个Web App链接,即可用OVERLAY模式打开:
var link = CardService.newOpenLink()
  .setUrl("你的Web App部署URL")
  .setOpenAs(CardService.OpenAs.OVERLAY);

注意:部分网站可能设置了X-Frame-Options禁止被iframe嵌入,这种情况下该方案无效。


内容的提问来源于stack exchange,提问作者Avula Vijay Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 08:08:22