onInstalled opens blank new tab on mobile - google-chrome

I have a Chrome extension that I'm testing on mobile (Kiwi Browser). The below code snippet works fine on desktop but not on mobile:
background.js
chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason == 'install') {
let install_window = window.open('https://www.google.com', '_blank');
install_window.opener = null;
}});
manifest.json
{
"app": {
"background": {
"scripts": ["background.js"]
}
},
"manifest_version": 2,
"name": "My App",
"version": "0"
}
What is the difference between desktop and mobile that would make this be the case?

From #wOxxOm in the comments:
Use the extensions API like chrome.tabs.create instead of window.open

Related

Keyboard Shortcuts for chrome extension can be seen in chrome://extensions/shortcuts but not working

This is a chrome extension which clears the input fields of the webpage. it works perfectly fine when I click at the extension.
I tried to give a keyboard shortcut to it. it was working at first but next day when I opened chrome extension was not there(maybe because I kept my extension in my chrome's profile folder at /home/user/.config/google-chrome/Profile 3/Extensions/). so chrome might have not recognised and removed it because it's not from store.
I added it again but this time keyboard shortcut was not working. I don't have any knowledge of developing extensions. I just looked up at the google.developer guides and created this.
// manifest.json
{
"name": "Reset Answers",
"description": "Resets checkboxes, radio button, Input Text!",
"version": "0.0.0.1",
"manifest_version": 3,
"background": {
"service_worker": "background.js"
},
"permissions": ["activeTab", "scripting"],
"action": {},
"commands": {
"_execute_action": {
"suggested_key": "Alt+C",
"description": "clears input fields"
}
},
"icons": {
"16": "/images/icon16.png",
"48": "/images/icon48.png",
"128": "/images/icon128.png"
}
}
// background.js
chrome.action.onClicked.addListener((tab) => {
chrome.scripting.executeScript({
target: {tabId: tab.id},
func: clear,
});
});
function clear() {
var elements = document.getElementsByTagName("input");
for (let i = 0; i < elements.length; i++) {
if (elements[i].type == "text" || elements[i].type == "number") {
elements[i].value = "";
} else if (elements[i].type == "radio" || elements[i].type == "checkbox") {
elements[i].checked = false;
}
}
}
chrome.commands.onCommand.addListener((command) => {
});
I tried calling clear function inside that event listener function is also not working.
chrome://extension/shortcuts page shows the extension and the shortcut like this but its not working.
Alt+C is not being used for any other keyboard shortcut on my pc. What I am doing wrong here?
Certain operating system and Chrome shortcuts (e.g. window management) always take priority over Extension command shortcuts and can not be overwritten.
The following sample outputs to console.log when Ctrl+Shift+1 is entered.
manifest.json
{
"name": "hoge",
"version": "1.0",
"manifest_version": 3,
"commands": {
"command1": {
"suggested_key": "Ctrl+Shift+1",
"description": "hoge"
}
},
"background": {
"service_worker": "background.js"
}
}
background.js
chrome.commands.onCommand.addListener((c) => {
switch (c) {
case "command1":
console.log("command1");
break;
}
});

Why does it show "Visit Website" and not Add extension?

I would like publish a website (web app) on our intranet as chrome app in the google web store.
I want to publish this app to all Computers in my domain, I've seen that I can do this with the GPO of Google and it works with every extension but not with mine.
So the problem I ran into is that if I publish my app in the chrome web store you can't download it. It only says "Visit Website". As shown in the picture here: Visit Website Button in the web store
This is how my manifest.json looks like:
{
"manifest_version": 2,
"name": "Support-Ticket",
"version": "1.0",
"icons": {
"128": "128.png"
},
"app": {
"urls": [
"https://intranet.*.com/example"
],
"launch": {
"web_url": "https://intranet.*.com/example"
}
},
"permissions": [
"notifications"
]
}
I've tested it with another little app where the manifest looks like this:
{
"name": "Support Test",
"version": "1.0",
"icons": {
"128":"128.png"
},
"manifest_version": 2,
"browser_action": {},
"permissions":[
"tabs"
],
"background":{
"scripts": ["background.js"],
"persistent": false
}
}
And the .js like this:
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({'url': chrome.extension.getURL('index.html')}, function(tab) {
// Tab opened.
});
});
I would like to have this website as chrome app and than install it on all computers in my domain with a shortcut in the Start Menu or Desktop.
Update:
I managed to create the app and display the intranet on the app with the html tag "webview".
Now it looks like this:
Window Frame
Does anyone know how I can change the color of the window frame to a darker grey?

js file not visible in Chrome Extension debugger

I have a simple app that I'm using to learn Chrome Extensions.
I cannot get break points to work in mainscript.js file in the debugger.
I couldn't see mainscript.js under Pages or Content Scripts.
I can see it when I load Filesystem and apply breakpoints but they are not breaking.
The alert is being displayed.
How do I set break points that work in mainscript.js?
Manifest:
{
"name": "Enable/Disable",
"version": "1.0",
"manifest_version": 2,
"description": "Enables/Disables",
"permissions":
[
"http://xxx.xxx.xxx.xxx/*",
"activeTab"
],
"browser_action":
{
"default_icon":
{
"16": "images/Icon_ENABLED.png"
}
},
"background":
{
"scripts": ["background.js"]
}
}
background.js:
chrome.browserAction.onClicked.addListener
(
function(tab)
{
chrome.tabs.executeScript(tab.id, {file: "mainscript.js"});
}
);
mainscript.js
alert('Mainscript');

chrome extension - update tab without changing url

I'm building a small chrome extension, that can open an page in a proxy
for example i'm opening www.mysite.com, and the clicking on my extension button, and it update the page to www.myproxy.net/q=www.mysite.com.
it's working like a charm, but i want to hide the chnage in the adress bar, so the url will remain the original site.
i made a few searches, but can't find out how to do such a thing.
can you please help me?
thanks
my manifest file
{
"name": "proxy",
"version": "1",
"browser_action": {
"default_icon" : "icon.png"
},
"permissions": ["tabs"],
"manifest_version": 2,
"background":{
"scripts": ["popup.js"]
},
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+B",
"windows": "Ctrl+B"
}
}
}
}
my popup.js
chrome.browserAction.onClicked.addListener(function(activeTab){
chrome.tabs.query({active: true, currentWindow: true}, function(tab) {
var newURL = "http://myproxy.net/?q=" + tab[0].url;
chrome.tabs.update(undefined, {url: newURL});
});
});
AFAIK, this is not possible via Chrome API. The fact that you couldn't find searches means it's not doable yet. Unless maybe, you can write your own implementation.
You can use history.pushState or history.replaceState to do this. Refer to this article https://developer.mozilla.org/en-US/docs/Web/API/History_API
Example:
On the page of www.myproxy.net/q=www.mysite.com, add a script
history.pushState( {} , '', '/' );

Chrome Extension background scripts aren't being loaded

My chrome extension background script is not being loaded. I followed Googles guide for them but still nothing. I'm not sure if there is another way to check but it isn't in Inspect Element and what the script should be doing isn't happening.
http://developer.chrome.com/extensions/background_pages.html
manifest.json file
{
"manifest_version": 2,
"name": "WebDevFriend",
"description": "blah blah blah",
"version": "1.0",
"permissions": [
"bookmarks",
"tabs",
"http://*/*" ],
"background": {
"scripts": ["js/settings.js"],
},
"browser_action": {
"default_icon": "images/icon.png",
"default_popup": "html/popup.html"
}
}
settings.js file
chrome.windows.onCreated.addListener(function(window){
chrome.windows.getAll(function(windows){
var length = windows.length;
if (length == 2) {
chrome.tabs.executeScript(null, {file: "content_script.js"});
}
});
});
document.write('hello');
First you can't view the background page like a regular html page.
The only way is to view its contents with the Chrome Developer Tools.
just click on generated_background_page.html in the extensions section of your browser.
Second use the console.log() statement to log messages.