javascript - 我的 react 应用程序中有一个 google chrome 扩展程序。我需要知道文档的哪一部分可以帮助我
问题描述
所以基本上我有一个 chrome 扩展程序创建反应应用程序。我想制作一个功能,如果我点击一个特定的站点并将其重定向到一个选项卡然后 - 如果扩展程序当前已添加到浏览器。我需要显示一个当我们在单击特定按钮时重定向模式。
我不知道如何使用 Chrome 扩展 API 来实现它。这是我添加和删除扩展的代码。
if (details.reason === "install") {
Background.initStorage(null).then(({ extId }) => {
// Should be called on install of extension
Background.fetchUserCountry();
// Opens thank-you in current tab
chrome.tabs.query({ currentWindow: true, active: true }, tabs => {
let url = new URL(tabs[0].url);
let refString = "";
for (let x = 1; x <= 6; x++) {
if (url.searchParams.get(`ref${x}`)) {
refString += `&ref${x}=${url.searchParams.get(`ref${x}`)}`;
}
}
chrome.tabs.create({ url: Config.wwwServer + '/api/install?app_uid=' + extId + '&v=' + Config.version + '&token=' + Config.apiToken + '&r=thankyou' + refString }, tab => {
const listener = function (tabId) {
if (tabId === tab.id) {
chrome.tabs.get(tabId, tabResult => {
if (tabResult) {
chrome.tabs.executeScript(tabId,
{ code: "var toolbar = document.createElement('TOOLBAR'); toolbar.id = 'browserappinstalled'; toolbar.setAttribute('app_uid', '" + extId + "'); toolbar.setAttribute('version', '" + Config.version + "'); document.body.appendChild(toolbar);" },
() => console.log("Extension installed", extId)
);
}
});
}
chrome.tabs.onUpdated.removeListener(listener);
};
chrome.tabs.onUpdated.addListener(listener);
});
});
chrome.runtime.setUninstallURL(Config.apiServer + '/ext/uninstall?app_uid=' + extId + '&v=' + Config.version);
chrome.tabs.query({ 'url': Config.lpUrls }, tabs => {
tabs.forEach(tab => chrome.tabs.remove(tab.id))
});
});
} else if (details.reason === 'update') {
// Should be called on update of extension
Background.fetchUserCountry();
Background.initStorage(null);
}
});
解决方案
推荐阅读
- python - 来自行的 Pandas 层次索引
- c# - ProgressBar 值的标签未出现
- amazon-web-services - 面向 Internet 的服务器与生产服务器
- r - 如何从 DBI 包中获取某些函数的 SQL 翻译
- android - API 28 Android 中未执行的方法
- php - 表单提交 Bootstrap Dropdown 数据
- php - 搜索数据透视表 Eloquent
- android - 由于 SDK,flutter_oauth 版本解析失败
- javascript - 选中多个单选按钮,取消选中单选按钮组
- command-prompt - “protoc”不是内部或外部命令、可运行程序或批处理文件 Windows