microsoft-edge-extension - 在 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]}`} );
}
});
});
解决方案
推荐阅读
- ruby-on-rails - 使用 Roo gem 导入 CSV 时拒绝不在关联表中的项目而不是创建新记录
- python - python中的Ode求解器
- java - Java 字符串缩短器
- php - 来自sql表的echo变量的PHP变量
- python - pygame 的导入模块适用于 Jupiter 笔记本,但不适用于 IDLE (Mac)
- java - java,通过创建 Throwable 对象来抛出未经检查的异常
- node.js - 部署到 Heroku 失败
- java - 我应该把while循环/布尔值放在哪里?
- html - 如何使html按钮像锚标记一样重定向
- sql - 如何在 Visual Studio asp.net 项目中从远程数据库设置本地数据库?