I want to create a new custom chrome extension to open a web URL or custom page in new window.
For adding a new chrome extension 2 files are mandatory
Here is the example to create a new custom chrome extension to open a web URL or custom page in the new chrome window.
Create a new folder and add the above two files inside the folder.
And your manifest.json file will look like this:
{ "manifest_version": 2, "name": "New Window", "version": "0.1", "permissions": [ "https://github.com/", "tabs" ], "browser_action": { "default_icon": "icon.png", "default_title": "Extension into New Window" }, "background": { "scripts": ["background.js"] } }
Here the icon.png is the chrome extension icon. Keep the icon root of the folder. 3. And your background.js file will look like:
/**
* 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});
}
});
In the new window size that you can define the width and height. The else part is to focus on the same window id after minimizing the new window. Find the below steps to launch the chrome extension in your local (develop mode) Steps :
For code pool: https://github.com/Nayana-chandran/chrome-new-window-extension
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With