[FAQ] chrome.runtime.onMessage 问题, Unchecked runtime.lastError: The message port closed before a response was received

通过llama.cpp与羊驼聊天的网页界面- 详解 Serge 的启动使用

 

  // quasar background-hook.js
  chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    if (request.accessToken !== '') {
      chrome.storage.local.set({ accessToken: request.accessToken }, () => {
        sendResponse({ farewell: 'success' })
      })
    }
    // Fix, Unchecked runtime.lastError: The message port closed before a response was received.
    return true
  })

 

Refer:chrome.runtime.onMessage

Refer:https://stackoverflow.com/questions/54126343/how-to-fix-unchecked-runtime-lasterror-the-message-port-closed-before-a-respon

Link:https://www.cnblogs.com/farwish/p/12236444.html

posted on 2020-01-27 17:45  ercom  阅读(690)  评论(0编辑  收藏  举报