首页 > 解决方案 > 在 MS Edge 扩展中持久化数据

问题描述

我想为 Edge 编写一个扩展,我想在特定站点的情况下重定向到另一个站点并返回本地网络。不幸的是,在从重定向页面返回后,Edge 既不保存数据也不保存在 sessionStorage、IndexedDB 或扩展中的局部变量中,因此这两个页面相互打乒乓球。该扩展程序适用于 Chrome。我在某处读到它是 Edge 中的一个错误,但我不知道解决方法是什么,拜托。

manifest.js

  {
    {
     "manifest_version": 2,
     "name": "PopUp",
     "version": "1.0",
      "background": { "scripts": ["background.js"] },   
      "permissions": ["activeTab", "tabs", "http://*/*", "https://*/*"],
      "icons": {
      "16": "icons/logo16.png",
      "32": "icons/logo32.png",
      "48": "icons/logo48.png",
      "128": "icons/logo128.png"
    }
  }

背景.js

const apps = [
  ['AAA', 'AAA/aaa'],
  ['BBB', 'BBB/bbb'],
  ['CCC', 'CCC.xxx.yy']
];

let tabToUrl = new Map();

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
        const url = tabs[0].url;
        let domain = (new URL(url));
        domain = domain.hostname.replace('www.','').toLowerCase();
        
        const i = apps.findIndex(u => domain.includes(u[1]));   
        const hasDomain = [...tabToUrl.entries()]
        .filter(({ 1: v }) => v === domain)
        .map(([k]) => k);
        if (i > -1 && hasDomain.length === 0) {
            
            tabToUrl.set(tabs[0].tabId, domain);
            chrome.tabs.update( tabs[0].id, { url: `http://popup.xxx.yy?title=${apps[i][0]}`} ); 
        } 
    });
}); 

解决方案

标签: microsoft-edge-extension

解决方案


推荐阅读