javascript - 为 Firefox 扩展设置弹出窗口标题
问题描述
我正在构建一个可以在多个浏览器中运行的浏览器扩展。单击浏览器操作时,会创建一个显示扩展页面的弹出窗口。Chrome 使用弹出页面的标题标签作为弹出窗口的标题,但 Firefox 没有。
相反,我得到以下信息:
为什么 Firefox 不使用页面标题?为了修复它,我在 windows.create 回调中设置了窗口标题,但这也不起作用。
这是打开弹出窗口的 background.js 脚本。
'use strict';
let browser = (function () {
return window.msBrowser ||
window.browser ||
window.chrome;
})();
var popupWindowId = false;
browser.browserAction.onClicked.addListener(function() {
// Open the popup if not already open. If open, focus on it.
if(popupWindowId === false) {
popupWindowId = true;
browser.windows.create({
'url': 'index.html',
'type': 'popup',
'height': 525,
'width': 350
}, function(win) {
win.title = 'My Title';
popupWindowId = win.id;
firefoxWorkaroundForBlankPanel();
});
return;
} else if(typeof popupWindowId === 'number'){
// The window is open, and the user clicked the button.
// Focus the window.
browser.windows.update(popupWindowId, { focused: true });
}
});
browser.windows.onRemoved.addListener(function (winId){
if(popupWindowId === winId){
popupWindowId = false;
}
});
// workaround for bug https://bugzilla.mozilla.org/show_bug.cgi?id=1425829
// bug causes popup to appear blank until resized
async function firefoxWorkaroundForBlankPanel () {
const {id, width, height} = await browser.windows.getCurrent();
browser.windows.update(id, {
height: height + 1
});
}
解决方案
不幸的是,您无法从弹出窗口标题中删除扩展 URL。根据这个Mozilla 错误报告讨论,这是故意的,以防止恶意扩展的欺骗/网络钓鱼尝试(例如,通过欺骗用户扩展弹出窗口是浏览器 UI 的一部分)。但至少他们可能会将其更改为在窗口标题中显示“扩展 [扩展名称]”,而不是丑陋的扩展 URL。
推荐阅读
- python - 将 Plotly Dash 嵌入 Flask 应用程序
- php - 如何检查是否允许在元素名称的开头或内部使用 unicode 字符
- bazel - 我应该如何设置 bazel 工作区?
- ios - 在项目中插入 CoreML 模型会导致错误
- vue.js - 如何使用 Vue.js 维护原始数组排序顺序
- javascript - 如何从编辑器制作csv文件
- firebase - Docker 容器上应用程序的 Google Compute 引擎的 Firestore 授权
- c - 了解#define LPC_CCAN_API ((CCAN_API_T *) (LPC_ROM_API->candApiBase)) 这一行
- c# - 更改 Xamarin 表单中的语言
- proxy - 我可以使用一个数据库同步两个 PRTG 部署吗?