With the chrome.contentSetting API from Chrome Extensions API, you can change the allow/block/ask state of let's say notification for a website. But the problem I can see now is that it disables the configurable-ness of the setting, for some reason, saying "Blocked by an extension" instead of showing a toggle icon button.
e.g. When I do this:
chrome.contentSettings.notifications.set({
'primaryPattern': "*://*.twitter.com/*",
"setting": 'block',
},
details => {
console.log(details)
})
It becomes something like this below, grayed out the selection, unable to manually toggle them anymore.
Is this a bug, or a feature? Is it possible to workaround this problem?
Related
I'm making a chrome extension and using page_action instead of browser_action because I need this extension for only one specific url. I'm using declerativeContent for activating the page_action;
// When the extension is installed or upgraded ...
chrome.runtime.onInstalled.addListener(function() {
// Replace all rules ...
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
// With a new rule ...
chrome.declarativeContent.onPageChanged.addRules([
{
// That fires when a page's URL contains ...
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { hostEquals: 'www.example.com', schemes: ['https'] },
})
],
// And shows the extension's page action.
actions: [ new chrome.declarativeContent.ShowPageAction() ]
}
]);
});
});
In normal tabs of chrome, there is no problem. Page_action works exactly the way I want. But in pop-up windows, there is a problem. I mean, there is page that contains links to pop-up pages. When I click to them, pop-up windows open but I can't see the page_actions in the address bar.
What could be the problem?
Unfortunately, Google Chrome extensions doesn't provide page_action icon on the adress bar in pop-up windows. But still, extension works on that window. You should think other ways to make your extension functional.
is there any way for a Chrome Extension to change the behavior of the Google Chrome Bookmark Star Button?
What I want to do:
I want to change the icon of the star (both, the white and the filled yellow version)
When new star button is clicked, it should add a bookmark to Google Chrome just like the original way the button works, but display a custom form instead of Googles default form.
Is that possible? I have not found any way to alter "built-in" functionality in Google Chrome.
However, Google itself does exactly what I want with this extension: https://chrome.google.com/webstore/detail/bookmark-manager/gmlllbghnfkpflemihljekbapjopfjik
By now, I have only found a way to alter the "bookmarks" page itself (https://developer.chrome.com/extensions/override)
Any hints on how to do that?
Thanks!
The Bookmark Manager App added this to its manifest:
"chrome_ui_overrides" : {
"bookmarks_ui": {
"remove_button": "true",
"remove_bookmark_shortcut": "true"
}
},
(as outlined here: https://developer.chrome.com/extensions/ui_override)
However, that seems to work only in Dev channel Chrome with --enable-override-bookmarks-ui=1 start argument or for the Google Bookmark extension itself.
I'm currently writing a chrome extension that has it's own panel in the Devtools. Although I'm facing an issue. I'm trying to trigger some action in the background page when the Devtools panel of a specific tab is closed.
I tried adding this to devtools.js :
window.onbeforeunload = function(event) {
port.postMessage({action: 'disableTab', tabId: tabID});
return "Are you sure you want to navigate away?";
};
Although the confirmation is never displayed and the message is never posted.
I think that it's because my devtools.html / devtools.js file isn't the one that is handling the main Devtools panel. it' only appended to it, something like that.
I'm still searching for an answer, anyone knows how I could achieve that ?
Edit:
I just noticed that this app is doing exactly what I want! https://developers.google.com/speed/pagespeed/insights_extensions
Run an analysis, then try closing the devtools, you'll be prompted.
I am trying to write a JavaScript function that will open my extension like when the extension icon is clicked. I know how to open my extension in a new tab:
var url = "chrome-extension://kelodmiboakdjlbcdfoceeiafckgojel/login.html";
window.open(url);
But I want to open a pop-up in the upper right corner of the browser, like when the extension icon is clicked.
The Chromium dev team has explicitly said they will not enable this functionality. See Feature request: open extension popup bubble programmatically :
The philosophy for browser and page action popups is that they must be triggered by user action. Our suggestion is to use the new html notifications feature...
Desktop notifications can be used progammatically to present the user with a small HTML page much like your popup. It's not a perfect substitution, but it might provide the type of functionality you need.
Chrome team did create a method to open the popup programmatically, but it's only enabled as a private API, and plans to make it generally available have stalled due to security concerns.
So, as of March 2018 as of now, you still can't do it.
Short answer is that you cannot open browserAction programmatically. But you can create a dialog with your content script which emulates your browserAction and display that isntead (programmatically). However you won't be able to access your extension's background page from this popup directly as you can from your popup.html. You will have to pass message instead to your extension.
As mentioned there is no public API for this.
One workaround I have come up with is launching the extension as an iframe inside a content script with a button click. Whereby the background script emits the extension URL to the content script to be set as the iframe's src, something like below.
background.js
browser.runtime.onMessage.addListener((request) => {
if (request.open) {
return new Promise(resolve => {
chrome.browserAction.getPopup({}, (popup) => {
return resolve(popup)
})
})
}
})
content-scipt.js
const i = document.createElement('iframe')
const b = document.createElement('button')
const p = document.getElementById('some-id')
b.innerHTML = 'Open'
b.addEventListener('click', (evt) => {
evt.preventDefault()
chrome.runtime.sendMessage({ open: true }, (response) => {
i.src = response
p.appendChild(i)
})
})
p.appendChild(b)
This opens the extension in the DOM of the page the script is running on. You will also need to add the below to the manifest.
manifest.json
....
"web_accessible_resources": [
"popup.html"
]
....
You could emulate the popup by displaying a fixed html element on the page in the same location the popup would be and style it to look like the popup.
I had the same requirement: When the user clicks on the extension icon a small popup should open. In my case, I was writing an extension which will give updates on selective stocks whenever the icon is clicked. This is how my popup looked.
If you were having the same requirement then please read the answer below.
This is how my manifest.json file looked.
All the heavy lifting was handled by manifest.json file only. There is a section browser_action inside which there is a key called default_popup, just put the name of the HTML file that you want the popup to display.
I wanted my extension to work on all the pages that's why I added the attribute matches under content_scripts. I really didn't need to put the jquery file jquery-3.2.1.js inside the js array but the extension manager was not allowing me to keep that array empty.
Hope this helps, do comment if you have any doubt regarding the answer.
Is there any API to be used to add a custom item into the chrome context menu?
For example:
Now, I wanna add a "send to ..." item to context menu(right click), when it is clicked the contents selected in the webpage will be sent to someone.
I searched the chrome APIS and found that chrome.experimental.contextMenu is competent for my requirement, however it is experimental API so something like "path_to_chrome.exe --enable-experimental-extension-apis" will be added.
Any other solutions?
Now (for long time) you have an option.
Add this permission to your manifest.json file
"permissions": ["contextMenus"]
Then, something like that will do the trick:
chrome.contextMenus.create({
'title' : 'Open this select text %s',
'contexts' : ['selection'],
'onclick' : function(info, tab) {
console.log('Selected link: ' + info.selectionText);
}
});
Good luck.
Using contextMenu is the one and only way (outside of hacking on the Chromium source), but the API should be graduating from experimental when Google Chrome 6 gets released to the stable channel.