I am working on a Mozilla Firefox extension that is creating a new alarm.
Here is the code in the manifest.json file:
{
"manifest_version": 2,
"name": "alarms-test",
"version": "1.0",
"content_scripts":
[
{
"matches": ["https://developer.mozilla.org/*"],
"js": ["alarms-test.js"]
}
],
"permissions":
[
"alarms"
]
}
Here is the code in the alarms-test.js file:
console.log("alarms-test: start");
const delayInMinutes = 1;
browser.alarms.create({delayInMinutes});
console.log("alarms-test: end");
Here are the steps that I am following:
In Mozilla Firefox, go to about:debugging
Click on This Firefox then Load Temporary Add-on...
Browse your local files to select the manifest.json file
Go to https://developer.mozilla.org/en-US/
Press F12 then click on the Console tab
See the output
Expected output:
alarms-test: start
alarms-test: end
Current output:
alarms-test: start
It means that something went wrong with the lines 2 and 3 of alarms-test.js.
Do you see what I forgot please?
Thank you.
Best regards.
Related
According to the documentation the following should do it:
app.on("open-file", (event, path) => {
event.preventDefault();
console.log("OPEN FILE???");
});
The console log is never called. I have tried:
Choosing "open with" and the application by right clicking on a file.
Use open with while the app is open.
Dragging a file on the dock icon.
It might be quite significant how I build it too. I use electron-builder and have this in my package.json:
"build": {
"appId": "com.myname.someid",
"mac": {
"fileAssociations": [
{
"ext": [
"mp3"
]
}
]
}
}
Then I run electron-builder after installing it.
I have retested it in electron-quick-start and after following the above steps it still fails.
According to this tutorial this is also how you should do it:
https://roysegall.medium.com/electron-open-with-for-mac-osx-f215a1fe2ce1
How do I configure my self-distrubuted firefox webExtension to auto-update, I have tried following MDN update doc but still unable to update.
My web Extension is hosted on a sub-domain name like
"https://files.example.com/myfile/extension.xpi"
My updates.json file resides at the same location with my .xpi file
This is a prototype of my updates.json
{
"addons": {
"updates": [ { "version": "1.2",
"update_link": "https://files.abc.com/myfiles/extension-1.2-an+fx.xpi" },
{ "version": "1.3",
"update_link": "https://files.abc.com/myfiles/extension-1.3-an+fx.xpi" }
]
}
}
This is the gibberish I get from browser console
1535658478365 addons.update-checker WARN onUpdateCheckComplete failed
to parse update manifest: [Exception... "Update manifest is missing a
required addons property." nsresult: "0x80004005 (NS_ERROR_FAILURE)"
location: "JS frame ::
resource://gre/modules/addons/AddonUpdateChecker.jsm ::
getRequiredProperty :: line 120" data: no] Stack trace:
getRequiredProperty()#resource://gre/modules/addons/AddonUpdateChecker.jsm:120
parseJSONManifest()#resource://gre/modules/addons/AddonUpdateChecker.jsm:130 onLoad()#resource://gre/modules/addons/AddonUpdateChecker.jsm:309 UpdateParser/<()#resource://gre/modules/addons/AddonUpdateChecker.jsm:241
It looks like your 'updates.json' is missing the add-on name and XPI hash. I would also test without the "+" in the file name, I think that caused me issues (Due to hosting server).
To view your add-ons UUID (ex "ADDONNAME#test.com") log into the developer hub, click edit information, then look under technical information. To generate an update_hash of your XPI file I would recommend VSCryptoHash, but any other program that generates a cryptographic hash will work.
{
"addons": {
"ADDONNAME#test.com": {
"updates": [
{ "version": "1.0.0",
"update_link": "https://files.abc.com/myfiles/extension-1.2-fx.xpi" ,
"update_hash": "sha256:blahblah" }
]
}
}
}
The console error says your manifest is missing something too. Here is an example based on mine that works.
"applications": {
"gecko": {
"id": "ADDONNAME#test.com",
"strict_min_version": "50.0",
"update_url": "https://webpage/Updatefile.json"
}
},
This may sound dumb, but I want to make a link open in a new tab whenever the icon in the toolbar is left-clicked. I've never made a Firefox addon before, and I'm pretty clueless on how you'd go about doing that.
You need browserAction in manifest.json, tabs.create and browserAction.onClicked.
Inside manifest.json:
"browser_action": {
"browser_style": true,
"default_icon": {
"32": "icons/icon-32.png"
}
}
Inside background.js:
browser.browserAction.onClicked.addListener((tab) => {
browser.tabs.create({url: "https://google.com"}); //
// or
browser.tabs.duplicate({tabId: tab.id}); // duplicate current tab, same as doing browser.tabs.create({url: tab.url}); but better (navigation history is kept)
});
Don't forget to ask for the "tabs" or "activeTab" permission in manifest.json.
"permissions": ["tabs", "activeTab"]
And don't forget to register background.js
"background": {
"scripts": ["background.js"]
}
I try get tabs of current brouser window
var tabs = require("sdk/tabs");
and catch all new tabs
tabs.on('load', function(tab) {
console.info( tab.url );
});
if I run firefox by jpm run, all work fine. But if I build the xpi and install it to firefox then I'm getting tabs by other empty windows (if I call tabs.open opening new windows)
How fix it?
Now I'm trying the following simple example:
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var button = buttons.ActionButton({
id: "mozilla-link",
label: "Visit Mozilla",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state) {
tabs.open("http://www.mozilla.org/");
}
And this example works only if I run "jpm run".
if I build the extension and simple run the firefox (with the addon), the button do not created.
I'm thinking that your xpi can not locate the icons, so your plugin seems not working.
The icons should be in your ./data directory and furthermore in your package.json it is a good practice to specify your main. The file hierarchy of your working extension is:
├--data/
├-- icon-16.png
├-- icon-32.png
├-- icon-64.png
├--lib/
├-- main.js
├--package.json
The package.json looks like:
{
"name": "stackexample",
"title": "stackexample",
"id": "mail#mail.com",
"description": "An stackoverflow example",
"author": "mail#mail.com",
"main": "./lib/main.js",
"version": "0.0.1"
}
In firefox after 'ready' event has been emitted, all properties relating to the tab's content can be used.You cannot access tab's properties on load event.
Please refer to this link of addon sdk tabs ready event
I found answer
If set setting history
"Never remember history" i got the problem
if set
"Remember history" problem has gone
it's very strange, i know
Hope you can help me. I need to call an executable jar from an Chrome-Extension. By research I found https://developer.chrome.com/extensions/messaging#native-messaging is the way to go.
So I first edited the manifest of my extension and added:
"permissions": [
"nativeMessaging"
],
I can see in the Extensions overview, that the permission is granted.
As I am operating on Windows I added a Registry-Key:
HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\myextension
with:
C:\path\to\myextension.json
the "myextension.json" contains:
{
"name": "myextension",
"description": "my extension",
"path": "myextension.bat",
"type": "stdio",
"allowed_origins": [
"chrome-extension://[key]/"
]
}
the myextension.bat contains:
#echo off
cd %windir%\system32
start calc.exe
(for testing just wanted to start the calculator)
in the js of my extension I try to call it by this:
var port = null;
var hostName = "myextension";
[...]
$(this).children(".abc").click(function() {
//alert("test");
port = chrome.runtime.connectNative(hostName);
alert(port);
message = {"text": "nachricht"};
port.postMessage(message);
});
But nothing happens. The first alert "test" would be executed. But other than that nothing happens.
I really don't know how to debug it, because I don't get any feedback by executing it. Hope you can help me.
/edit
Just saw that I get:
"Uncaught TypeError: undefined is not a function (anonymous function)"
at:
port = chrome.extension.connectNative(hostName);
or
port = chrome.runtime.connectNative(hostName);
/edit 2
Ok, now I got it to work when I use a button in the browser with: chrome.browserAction.onClicked.addListener(function() {
chrome.extension.connectNative('fbehost');
});
But when I want to call it from a button in the website it doesn't work:
$(this).children(".abc").click(function() {
alert("Test");
port = chrome.extension.connectNative("fbehost");
});
The alert works, but nothing else happens.