Firefox add-on background script stopped in new Firefox version - firefox

My Firefox add-on background script stopped working in the latest version of Firefox. I've been using this add-on without changes for over a year now and it has been working perfectly so something in the recent Firefox updates broke the add-on. I'm on version 106.0.1 now. When I go to debug add-ons I can see the background script is stopped.
In the manifest.json (version 2)
"background": {
"scripts": [
"background.js"
],
"persistent": false
},
In the background.js
chrome.runtime.onInstalled.addListener(() => {
console.log('Installed');
setUpdateAlarm();
});
chrome.runtime.onStartup.addListener(() => {
console.log('Startup');
setUpdateAlarm();
});
chrome.alarms.onAlarm.addListener((alarm) => {
console.log('Alarm: ' + alarm.name);
switch (alarm.name) {
case 'Refresh':
updateCache();
break;
}
});
function setUpdateAlarm() {
updateCache();
chrome.alarms.create('Refresh', { periodInMinutes: 3 });
}
Keep in mind that neither of these files have changed but Firefox has been updated.

Related

Electron: How do implement "open with" / have the "open-file" app event on MacOS called?

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

Websocket connection failing from Firefox extension

I have a Firefox extension which connects to a websocket server and sends a message. I packaged it with web-ext build, renamed the .zip to a .xpi. Last month I installed it in Firefox after setting xpinstall.signatures.required to false in about:config. I added the SSL key to the Firefox certificate manager. It worked for a month. Yesterday there was probably a Firefox update and now the extension is blocked becaue it is not signed. After some research, I found that the regular Firefox has not allowed unsigned extensions for a long time. It makes me wonder what version I had until yesterday; I am working on a Ubuntu 20.04 system I set up 2 months ago.
When the extension is loaded manually with about:debugging, the extension works as it did before (websocket creation is successful and a message is sent).
I read online that Firefox Developer edition allows unsigned extensions. But after following the exact same steps, I cannot get the extension to work with a .xpi or by temporarily loading the extension. It is the same error in both circumstances:
Firefox can’t establish a connection to the server at wss://localhost:9501/.
The extension has a manifest and a background script
manifest.json:
{
"description": "weblogging app",
"manifest_version": 2,
"name": "weblogger",
"version": "1.0",
"browser_specific_settings": {
"gecko": {
"id": "browser_logger#example.org",
"strict_min_version": "50.0"
}
},
"background": {
"scripts": ["background.js"]
},
"permissions": []
}
background.js:
var websocketArguments = 'wss://localhost:9501';
var connected = new Boolean(false);
var webSocket;
createWebsocket();
function onError(error)
{
console.log(`Error: ${error}`);
}
function createWebsocket()
{
webSocket = new WebSocket(websocketArguments);
webSocket.onerror = onWebSocketError;
webSocket.onopen = onWebSocketOpen;
}
function onWebSocketError(event)
{
console.log("WebSocket error observed:", event);
};
function onWebSocketOpen(event)
{
console.log("WebSocket open: ", webSocket.readyState);
webSocket.send("hello there");
connected = true;
};
Whatever the reason I could not get the extension to work when unsigned, it was just easier to get it signed.
https://addons.mozilla.org/en-CA/developers/

Cannot use import statement outside a module when running android app with firebase

Using nativescript-vue and can't make my app run after upgrading to latest version of nativescript.
"nativescript": {
"id": "xxx",
"tns-ios": {
"version": "6.5.1"
},
"tns-android": {
"version": "6.5.1"
}
},
App.js:
import Vue from "nativescript-vue";
import App from "./components/App";
const firebase = require('nativescript-plugin-firebase')
const {LocalNotifications} = require("nativescript-local-notifications")
firebase.init({
showNotifications: true,
showNotificationsWhenInForeground: true,
onMessageReceivedCallback: (message) => {
console.log('[Firebase] onMessageReceivedCallback:', {message});
LocalNotifications.schedule(
[{
id: 1,
title: message.data.title,
body: message.data.body,
silhouetteIcon: 'res://ic_app_icon',
thumbnail: "res://icon",
forceShowWhenInForeground: true,
notificationLed: true,
channel: i18n.t('messages_about_orders')
}])
.catch(error => console.log("doSchedule error: " + error));
}
}).then(
function () {
console.log("firebase.init done");
},
function (error) {
console.log("firebase.init error: " + error);
}
);
I run tns run android and right after I get Webpack build done in the console, I get these messages and a crash:
nativescript-plugin-firebase: /Users/butaminas/Local Sites/getfast.co.nz-courier-app/platforms/android/.pluginfirebaseinfo not found, forcing prepare!
nativescript-plugin-firebase: running release build or change in environment detected, forcing prepare!
Cannot use import statement outside a module
What could be the problem here? I have another, similar app and it is all working fine.
I figured it out. It was the problem with hooks folder in the project root directory.
I don't know why this happened but after removing the plugin (the hooks directory was not removed) I removed the hooks folder manually and then installed the plugin again - the problem disappeared.

Service-worker doesn't install only adds to home screen

I'm trying to install the pwa onto my mobile device. I only am able to add to home screen. Does anyone have any idea why this is happening?
To make your PWA installable you need to meet up the following requirments:
A web manifest,with the correct fields filled in.
The website to be served from a secure(HTTPS) domain.
An icon to represent the app on the device.
A service worker registered with a fetch eventhandler,to make the app work offline(this is only required by chrome for Android currently).
You must include your manifest file in section of your index.html,like this
<link rel="manifest" href="name.webmanifest">
Your manifest should contain the following fields,most of which are self explanatory.
{
"background_color": "purple",
"description": "Shows random fox pictures. Hey, at least it isn't cats.",
"display": "fullscreen",
"icons": [
{
"src": "icon/fox-icon.png",
"sizes": "192x192",
"type": "image/png"
}
],
"name": "Awesome fox pictures",
"short_name": "Foxes",
"start_url": "/pwa-examples/a2hs/index.html"
}
Now when the browser finds the manifest file with all requirements fulfilled,it will fire a beforeinstallprompt and accordingly you have to show the A2HS dialog.
NOTE:
Different browsers have different criteria for installation, or to trigger the beforeinstallprompt event.
Starting in Chrome 68 on Android (Stable in July 2018), Chrome will no longer show the add to home screen banner. If the site meets the add to home screen criteria, Chrome will show the mini-infobar.
For A2HS dialog:
Add a button in your document,to allow user to do the installation
<button class="add-button">Add to home screen</button>
Provide some styling
.add-button {
position: absolute;
top: 1px;
left: 1px;
}
Now in the JS file where you register your service worker add the following code
let deferredPrompt;
//reference to your install button
const addBtn = document.querySelector('.add-button');
//We hide the button initially because the PWA will not be available for
//install until it follows the A2HS criteria.
addBtn.style.display = 'none';
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI to notify the user they can add to home screen
addBtn.style.display = 'block';
addBtn.addEventListener('click', (e) => {
// hide our user interface that shows our A2HS button
addBtn.style.display = 'none';
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then((choiceResult) => {
if (choiceResult.outcome === 'accepted') {
console.log('User accepted the A2HS prompt');
} else {
console.log('User dismissed the A2HS prompt');
}
deferredPrompt = null;
});
});
});

Protractor file download test fails when headless chrome

I am having an issue with a protractor test. It was working, but now (even thought nothing has changed) it is not.
The test is just opening the app (web application) and clicking on a button to download an image. The download should start straight away.
The problem is that the next instruction after the download event throws an exception, Failed: chrome not reachable. I am using the latest chrome and chrome driver versions.
The capabilites section for protractor is like this:
capabilities: {
browserName: 'chrome',
loggingPrefs: { browser: 'ALL' },
chromeOptions: {
args: ['--headless', '--window-size=1240,780'],
},
}
I am reading about using DevTools to enable downloads in headless mode (Page.setDownloadBehavior), but so far no luck.
Does anybody have this issue too? Any clue how to fix it?
Thanks.
There could be another easy way to do it, but this is what I have done in my test suite.
I used got library, however, you can use any library to send an HTTP post request.
Discussion about setting download directory in headless chrome: https://bugs.chromium.org/p/chromium/issues/detail?id=696481
let got = require('got');
let session = await browser.getSession();
let sessionId = session['id_'];
let params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': downloadDir }}
await got.post('http://localhost:4444/wd/hub/session/'+ sessionId + '/chromium/send_command', {body: JSON.stringify(params)})
If you have not disabled ControlFlow in your protractor config, change ASync/Await to .then.
An easier solution is to add these lines to your protractor.conf.js:
exports.config = {
...
onPrepare() {
...
browser.driver.sendChromiumCommand('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: downloadsPath
});
}
};
From: https://bugs.chromium.org/p/chromium/issues/detail?id=696481#c196
Appendix
If you are to lazy to find a Download Path just paste this at the top of your protractor.conf.js:
var path = require('path');
var downloadsPath = path.resolve(__dirname, './downloads');
It will download the file to the e2e/downloads folder. Just use the same code in your tests to find out if the file downloaded.
This works for me:
chromeOptions: {
'args': [
'--headless',
'--disable-gpu',
'--test-type=browser',
'--disable-extensions',
'--no-sandbox',
'--disable-infobars',
'--window-size=1920,1080',
//'--start-maximized'
"--disable-gpu",
],
prefs: {
'download.default_directory': 'C:\\downloads',
'download.prompt_for_download':false,
'download.directory_upgrade':true,
"safebrowsing.enabled":false,
"safebrowsing.disable_download_protection":true
},
},

Resources