最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Firefox extension: launchWebAuthFlow not able to use sendResponse - Stack Overflow

programmeradmin0浏览0评论

I'm creating a web extension on Firefox using React

When I click on a button, a callback is called:

browser.runtime.sendMessage({ type: "auth", url: "url" })
    .then((response) => {
      console.log("Response:", response);
    })
    .catch((error) => {
      console.error("Error:", error);
    });

And, the background script is listening and indeed receives the message:

browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
    if (message.type === "auth") {
      browser.identity.launchWebAuthFlow({ url: message.url, interactive:true })
        .then((responseUrl) => {
          console.log("callback!")
          sendResponse({ success: true, url: responseUrl });
        })
        .catch((error) => {
          sendResponse({ success: false, error: error.message });
        });
  
      return true;
    }
  });

The OAuth call is going fine, the callback is called and the log "callback!" can be seen. But the message is never received back on React side

Here is my manifest:

{
  "manifest_version": 2,
  "name": "Open Link Extension",
  "version": "1.0",
  "description": "An extension that opens a link when a button is clicked.",
  "permissions": [
    "tabs",
    "identity",
    "activeTab",
    "webRequest",
    "<all_urls>",
    "cookies"
  ],
  "browser_action": {
    "default_popup": "html/popup.html"
  },
  "background": {
    "scripts": [
      "src/background.js"
    ],
    "persistent": false
  },
  "icons": {
    "48": "icon.png"
  }
}

Thanks for your help!

发布评论

评论列表(0)

  1. 暂无评论