chrome.identity.launchWebAuthFlow redirectURL未定义

问题描述

我正在开发一个浏览器扩展。以下使用chrome.identity.launchWebAuthFlow API的代码在一台机器上运行。我尝试使用浏览器的“加载未打包”功能将相同的代码加载到另一台计算机上,但是现在回调的redirect参数是undefined,而不是预期的URL字符串值。这导致整个事情失败。我回到了原来的机器上,使用相同的“ Load Unpacked”功能删除并再次添加了扩展名,现在它在该机器上也无法使用。在此期间,此代码或服务器没有任何更改。发生了什么事?

authenticateButton.addEventListener("click",() => {
  const redirectURL = encodeURIComponent(chrome.identity.getRedirectURL());
  const clientId = encodeURIComponent("ff");
  const authURL = `https://linksaver.io/oauth?client_id=${clientId}&redirect_uri=${redirectURL}`;

  return chrome.identity.launchWebAuthFlow(
    {
      interactive: true,url: authURL
    },redirect => {
      const parsed = new URL(redirect);
      const token = parsed.searchParams.get("token");
      chrome.storage.local.set({ token },() => {
        showlogout();
      });
    }
  );
});

解决方法

问题是,某些javascript已添加到oauth页中,从而拦截了请求并阻止了正确接收到重定向响应。