Change the Home Page in Chrome browser from Extension - google-chrome-extension

Does anyone know how to change the user's Home page in Chrome Browser from Chrome Extension?
I tried some solutions like document.setHomePage but it doesn't work.
In firefox, I am using the following code:
prefs.setCharPref('browser.startup.homepage', searchUrl);
Any suggestions?
Thanks.

The closest thing currently available is allowing your extension to override the "new tab" page. include this in your manifest:
{
"name": "My extension",
...
"chrome_url_overrides" : {
"newtab": "myPage.html"
},
...
}
However, your users may set their new tab page to any other url as their home page.

It is now possible to override the homepage through the chrome_settings_overrides option:
{
"name": "My extension",
...
"chrome_settings_overrides": {
"homepage": "http://www.homepage.com",
}
}

Related

Google Chrome "Override Pages" Extension

I'm trying to make simple extension to redirect newtab to other online URL. Code below works if I redirect to whatever local page inside the extension's folder.
"chrome_url_overrides": {
"newtab": "newtab.html"
},
but I would like to use external/online URL and if I simply put within the quotes like below it wont work as it's not allowed by chrome.
"chrome_url_overrides": {
"newtab": "https://stackoverflow.com/"
},
so I tried using JavaScript's different ways within the newtab.html, one example below
window.location.href = "https://stackoverflow.com/";
but this is not working either. Any ideas as to how else I could make it work?

Mozilla WebExtensions start page

I'm trying to make a custom start page in Firefox using WebExtensions.
In Chrome I can set page in manifest.json (chrome_url_overrides), but Firefox doesn't support this feature.
I made it trought chrome.tabs.onCreated.addListener and chrome.tabs.update, but I see the standard home page during the short time until the script processes.
How can I implement it more qualitatively through WebExtensions?
The bug to Support overriding newtab page from a webextension has been resolved and the fix has landed in Firefox 54 (Nightly, as of writing this answer). This means that you can use chrome_url_overrides in your manifest.json like you usually would. For example:
{
"manifest_version": 2,
"name": "Test",
"version": "1.0",
"description": "Test.",
"chrome_url_overrides": {
"newtab": "test.html"
}
}

Scanning Text through a chrome extension to auto launch links

I'm pretty new at chrome extensions and am trying to make a simple one that automatically launches links in my emails. I am going to modify it a bit later on, but for now, this is all I am trying to do. How do I have a chrome extension automatically read the text of the current tab that I am on, or when I open emails if I can get that specific? I have a manifest file set up and currently can make the extension button launch a link, but I'd rather have this happen automatically, as I don't want to hit a button to launch a link when I could just click the link itself.
manifest.json
{
"manifest_version": 2,
"name": "MT task launcher",
"description": "This extension launches Task Links in emails",
"version": "1.0",
"background": {
"scripts": ["task.js"]
},
"browser_action": {
"default_icon": "icon.png",
"default_title": "Email Task Launcher"
},
"permissions": [
"activeTab"
]
}
task.js
chrome.browserAction.onClicked.addListener(function(tab) {
var action_url = "http://www.reddit.com";
chrome.tabs.create({ url: action_url });
});
Take a look at Official Guide, for your purpose, I think you should use content scripts ( which are injected into current web page), then read the DOM and get all the links. To open the links, you can either call window.open() or by passing message then open them via chrome.tabs.create
There are two options to do that, it's either edit the local copy of the extension or to inject the call to the extension.
Inject code as a Content script, use the matching rules as defines in the manifest file
A background page file use the 'chrome.tabs.onUpdated' event. Also, use the 'chrome.tabs.executeScript' method to inject script.

Chrome Extension: Event Page For New Bookmark Events

I'm completely new to Chrome Extensions. I want the creation of a bookmark to trigger a xmlhttprequest. Right now, I'm just trying to get a new bookmark event to do a console.log and can't see what I'm missing.
Here is my manifest.json:
{
"manifest_version": 2,
"name": "Booky Desktop Integration",
"description": "Sends New Chrome Bookmarks To Your Booky Desktop.",
"version": "1.0",
"background": {
"scripts": ["background.js"],
"persistent": false
},
"permissions": [
"bookmarks",
"http://bookydesktop.com/"
]
}
Here is my js:
chrome.bookmarks.onCreated.addListener(function(id, bookmark) {
console.log("bookmark created");
});
What am I missing?
Your code works perfectly as written. You're probably not viewing the console for your background page. You need to:
Open chrome://extensions/ (or click "Extensions" in Chrome's "Settings" menu)
Ensure "Developer mode" is ticked in the top right
Open the console by clicking "_generated_background_page.html (Inactive)" in the "Inspect views" list under your extension
Each page in Chrome has its own console instance. You were looking at the consoles of ordinary web pages, instead of looking at the console for your background page.

Using console.log() in js [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Where to read console messages from background.js in a Chrome extension?
I am trying to write my first Google Chrome extension. All I am trying to do is is create an extension that writes a string, via console.log(), to the console when the extension's browser action icon is clicked.
Here is my manifest.json:
{
"name": "My Extension",
"description": "My Extension",
"version": "1.0",
"permissions": ["tabs"],
"background": {
"scripts": ["test.js"]
},
"browser_action": {
"default_title": "My Extension",
"default_icon": "icon.png"
},
"manifest_version": 2
}
And here is test.js:
chrome.browserAction.onClicked.addListener(function(tab) { console.log('testing'); });
I have the console open in Chrome but when I click my extension's icon nothing is displayed in the console. I've tried reloading the extension but it hasn't helped.
I am abviously doing something wrong.
Any advice would be much appreciated.
LT
Your script runs in the background page, so the message will be displayed in the background page's console.
Open the Extensions page.
Make sure that Developer mode is checked.
Under My Extension, click _generated_background_page.html to inspect it.
Click on the Console tab.

Resources