Nay*_*ran 4 javascript google-chrome-extension manifest.json
我想创建一个新的自定义 chrome 扩展程序以在新窗口中打开一个 web URL 或自定义页面。
要添加新的 chrome 扩展,2 个文件是必需的
以下是创建新的自定义 chrome 扩展程序以在新的 chrome 窗口中打开 Web URL 或自定义页面的示例。
创建一个新文件夹并将上述两个文件添加到文件夹中。
您的 manifest.json 文件将如下所示:
{ "manifest_version": 2, "name": "New Window", "version": "0.1", "permissions": [ "https://github.com/", "tabs" ], "browser_action": { "default_icon": "icon.png", "default_title": "扩展到新窗口" }, "background": { "scripts": ["background.js"] } }
这里的 icon.png 是 chrome 扩展图标。保留文件夹的图标根。3. 你的 background.js 文件将如下所示:
/**
* Listens for the app launching then creates the window
*/
var ba = chrome.browserAction;
// Function to open the chrome extension into new chrome window
var windowNotOpenTitle = 'Open popup window';
var windowIsOpenTitle = 'Popup window is already open. Click to focus popup.';
var popupWindowId = false; //popupWindowId can be true, false, or the popup's window Id.
ba.onClicked.addListener(function () {
let width= 1100;
let height= 650;
if(popupWindowId === false){
popupWindowId = true; //Prevent user pressing the button multiple times.
ba.setTitle({title:windowIsOpenTitle});
chrome.windows.create({
'url': 'https://github.com/',
'type': 'panel',
'width': width,
'height': height,
'left': (screen.width/2) - (width/2),
'top': (screen.height/2) - (height/2),
'focused': true
},function(win){
popupWindowId = win.id;
});
return;
}else if(typeof popupWindowId === 'number'){
//The window is open, and the user clicked the button., Focus the window.
chrome.windows.update(popupWindowId,{focused:true});
}
});
Run Code Online (Sandbox Code Playgroud)
在新的窗口大小中你可以定义宽度和高度。else 部分是在最小化新窗口后关注相同的窗口 id。查找以下步骤以在本地(开发模式)中启动 chrome 扩展 步骤:
代码池:https : //github.com/Nayana-chandran/chrome-new-window-extension
| 归档时间: |
|
| 查看次数: |
660 次 |
| 最近记录: |