为 Firefox 扩展设置弹出 window 标题
Set popup window title for Firefox extension
我正在构建一个可在多种浏览器中运行的浏览器扩展程序。单击浏览器操作时,将创建一个显示扩展页面的弹出窗口。 Chrome 使用弹出页面的标题标签作为弹出窗口的标题 window,但 Firefox 没有。
相反,我得到以下信息:
为什么 Firefox 不使用页面标题?为了修复它,我在 windows.create 回调中设置了 window 标题,但这也不起作用。
这是打开弹出窗口的 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
});
}
很遗憾,您无法从弹出 window 标题中删除扩展名 URL。根据这个 Mozilla bug report discussion 这是故意的,以防止 spoofing/phishing 恶意扩展的尝试(例如通过欺骗用户扩展弹出窗口 window 是浏览器的一部分 UI) .但至少他们可能会将其更改为在 window 标题中显示 "Extension [Extension name]" 而不是丑陋的扩展名 URL.
我正在构建一个可在多种浏览器中运行的浏览器扩展程序。单击浏览器操作时,将创建一个显示扩展页面的弹出窗口。 Chrome 使用弹出页面的标题标签作为弹出窗口的标题 window,但 Firefox 没有。
相反,我得到以下信息:
为什么 Firefox 不使用页面标题?为了修复它,我在 windows.create 回调中设置了 window 标题,但这也不起作用。
这是打开弹出窗口的 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
});
}
很遗憾,您无法从弹出 window 标题中删除扩展名 URL。根据这个 Mozilla bug report discussion 这是故意的,以防止 spoofing/phishing 恶意扩展的尝试(例如通过欺骗用户扩展弹出窗口 window 是浏览器的一部分 UI) .但至少他们可能会将其更改为在 window 标题中显示 "Extension [Extension name]" 而不是丑陋的扩展名 URL.