Mozilla WebExtensions start page - google-chrome-extension

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"
}
}

Related

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.

Click make popup disapear

I'm currently developping a chrome extension in order to watch youtube videos in a popup window while browsing an other website.
It works just fine, the problem is that if I click on a link or switch fullscreen app (Mac) the popup disapear, how can I make the popup bubble stay "for ever" ?
The manifest :
{
"manifest_version": 2,
"name": "One-Click Youtube",
"description": "Youtube on one click",
"version": "1.0",
"permissions": ["tabs" , "contextMenus"],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "ytplayer.html"
}
}
There is an always on top window api for apps. A demo is here: https://chrome.google.com/webstore/detail/floating-youtube/jjphmlaoffndcnecccgemfdaaoighkel
You cannot. The popup will always close and destroy the page when it loses focus.
This behavior is by design; you need a different UI, maybe open a window with type: "popup".
If and when window type "panel" becomes available (probably never), your question can be solved better.

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.

Can I use a chrome extension to add a widget to my website?

I'm playing with chrome extensions, trying to learn how to use them.
Is it possible for me to write an extension which injects a widget into my website whenever someone with the extension visits it? Can you recommend a sample application or tutorial that I can look at, which showcases something like this?
You can only inject JavaScript and CSS through Chrome extensions.
To inject the script or css your manifest.json should look something like this:
{
"name": "Website addon",
"version": "1.0",
"manifest_version": 1,
"description": "Addon for your website",
"content_scripts": [
{
"matches": ["*://yourWebsite.com/*", "*://*.yourWebsite.com/*"],
"js": ["yourJS.js"]
"css": ["yourCSS.css"]
}
]
}
This will add yourJS.js and yourCSS.css to all websites on yourWebsite.com
Here is a link to a tutorial from google: http://code.google.com/chrome/extensions/content_scripts.html

Change the Home Page in Chrome browser from 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",
}
}

Resources