google-chrome - 链接到 G-Cal 事件时如何修复 'Unchecked runtime.lastError: The message port closed before a response was received.'?

标签 google-chrome google-apps-script google-app-maker

我正在尝试生成一个链接,将用户直接带到所选的 Google 日历事件。

我生成的链接与您通过日历界面到达的链接相同,但是,当用户选择该链接时,它会加载一个空白页面,其中包含 Google 日历标题和 Keep/Tasks 侧边栏。没有实际内容加载,我得到了 Unchecked runtime.lastError: The message port closed before a response was received. 控制台错误。这是下面的代码,但正如我所说 - 链接是相同的。

var events = [];
  var today = new Date;
  var myEvents = CalendarApp.getDefaultCalendar().getEventsForDay(today);
  var calendarId = CalendarApp.getDefaultCalendar().getId();

  myEvents.forEach(function(event){
    var eventIdSplit = event.getId().split('@');
    var newRecord = app.models.Calendar.newRecord();

    newRecord.Date = event.getStartTime();
    newRecord.Title = event.getTitle();
    newRecord.Description = event.getDescription();
    newRecord.calendarLink = 'https://calendar.google.com/calendar/r/eventedit/' + (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId));

    events.push(newRecord);
  });

我搜索了错误,发现其他用户建议禁用所有扩展,但是,我没有运行任何扩展。

最佳答案

我发现了

newRecord.calendarLink = 'https://calendar.google.com/calendar/r/eventedit/' + (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId));

在日历链接的末尾生成几个 '=='。这些等号是中断的原因。

因此,将上面的代码修改为下面的代码就解决了这个问题:

newRecord.calendarLink = 'https://calendar.google.com/calendar/r/eventedit/' + (Utilities.base64EncodeWebSafe(eventIdSplit[0] + " " + calendarId)).replace(/=/g, "");

关于google-chrome - 链接到 G-Cal 事件时如何修复 'Unchecked runtime.lastError: The message port closed before a response was received.'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55805996/

相关文章:

google-apps-script - Google Apps 脚本,脚本已完成但未返回任何内容

javascript - 日期类谷歌应用程序脚本的日期错误

google-cloud-sql - Google App Maker 将记录保存到数据库每条记录需要 240 毫秒

javascript - "Back to Top"按钮仅在窗口滚动时可见(但在移动设备上不起作用)

javascript - IOS 10.3.1 Chrome 浏览器 CORS 失败

google-apps-script - 处理 UrlFetchApp.fetch() 中的 404 错误

google-app-maker - 如何从服务器脚本创建新记录

javascript - 如何在应用制作工具中按月份对列表进行排序?

google-chrome - 超出最大 IPC 消息大小

google-chrome - Chrome 对 Visual Studio 2017 无响应