firefox addon tabs.executeScript error on specific pages No window matching {"matchesHost":["<all_urls>"]} - firefox

I have a firefox webextension ported from chrome extension. The executeScript call fails on this site.
https://addons.mozilla.org/en-US/firefox/
I tested with multiple pages on this site and all are giving the same error
The bare-minimum code to reproduce this is
popup.js
document.addEventListener("DOMContentLoaded", function () {
chrome.tabs.query({"active": true}, function(tabs) {
chrome.tabs.executeScript(tabs[0].id, {"code": "console.log('Script executed in ' + document.location.href);"}, function(r) {
if(chrome.runtime.lastError) {
console.log(chrome.runtime.lastError);
document.body.innerHTML = 'Execute script Fail. check console';
} else {
document.body.innerHTML = 'Execute script Success';
}
});
});
});
manifest.json
{
"manifest_version": 2,
"name": "execscript_test",
"short_name": "execscript_test",
"version": "0.0.1",
"description": "desc",
"icons": {
"19": "images/icon19.png",
"38": "images/icon38.png",
"128": "images/icon.png"
},
"applications": {
"gecko": {
"id": "execscript_test#me.com",
"strict_min_version": "48.0"
}
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs",
"<all_urls>"
],
"browser_action": {
"browser_style": false,
"default_icon": "images/icon.png",
"default_title": "execscript_test",
"default_popup": "popup.html"
}
}
background.js - file is present but it is empty
popup.html
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
On https://addons.mozilla.org/en-US/firefox/addon/engrip-tracker/?src=search page I clicked on the browser button and got this error in browser console
Error: No window matching {"matchesHost":["<all_urls>"]}
Stack trace:
Async*#moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:8:4
Async*#moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:2:2
EventListener.handleEvent*#moz-extension://062a83b0-81f1-42f0-84a8-89ecdc2c08e0/popup.js:1:1
I thought it could be some url scheme issue but this happens even on https://addons.mozilla.org/en-US/firefox/
The same code works without error on chrome.
I am on FF v50. I tested this on FF nightly also (v53.0a1) and the error persists.
Is this something specific to this site? Or am I missing something here?

This is deliberate, it is covered in e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=1310082

Related

notifySuccess on saveEvent not working, seeing error in console

I'm trying to build a screen to save a connector and I cannot get the Save button to work. It throws a JavaScript error from deep inside Teams itself.
As you can see I'm using the latest stable version of Teams JS.
My code has been boiled down to as simple as can be made. It just inits and sets the Save button validity so it can be clicked.
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://res.cdn.office.net/teams-js/2.7.1/js/MicrosoftTeams.min.js" crossorigin="anonymous">
</script>
</head>
<body>
<p>Testing 6</p>
<script>
async function init() {
await microsoftTeams.app.initialize();
microsoftTeams.pages.config.setValidityState(true);
}
init();
</script>
</body>
</html>
If I load up the console in my web browser, this is the error I receive:
2023-01-25T03:00:00.927Z Received error from connectors {
"seq":1674609016862,
"timestamp":1674613638241,
"flightSettings":{
"Name":"ConnectorFrontEndSettings",
"AriaSDKToken":"d12...",
"SPAEnabled":true,
"ClassificationFilterEnabled":true,
"ClientRoutingEnabled":true,
"EnableYammerGroupOption":true,
"EnableFadeMessage":false,
"EnableDomainBasedOwaConnectorList":false,
"EnableDomainBasedTeamsConnectorList":false,
"DevPortalSPAEnabled":true,
"ShowHomeNavigationButtonOnConfigurationPage":false,
"DisableConnectToO365InlineDeleteFeedbackPage":true,
"RemoveAnchorHeader":true
},
"status":500,
"clientType":"SkypeSpaces",
"connectorType":"92a...",
"name":"handleMessageError"
}
The manifest file is also simple: it is the one downloaded from the Connector Dashboard (with the invalid part deleted and the schema version upgraded because the dashboard generates INVALID MANIFESTS). Because I've downloaded the file, the UUIDs and valid domains are perfect matches.
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.15/MicrosoftTeams.schema.json",
"manifestVersion": "1.15",
"id": "2ac21268...",
"version": "1.0.0",
"packageName": "com.Simple I/O (Development 3)",
"developer": {
"name": "Developer",
"websiteUrl": "https://3821-68-69-235-13.ngrok.io",
"privacyUrl": "https://3821-68-69-235-13.ngrok.io",
"termsOfUseUrl": "https://3821-68-69-235-13.ngrok.io"
},
"description": {
"full": "Simple I/O (Development 3)",
"short": "Simple I/O (Development 3)"
},
"icons": {
"outline": "outline.png",
"color": "color.png"
},
"connectors": [
{
"connectorId": "2ac21268...",
"scopes": [
"team"
],
"configurationUrl": "https://3821-68-69-235-13.ngrok.io/teams/connector"
}
],
"name": {
"full": "Simple I/O (Development 3)",
"short": "Simple I/O (Development 3)"
},
"accentColor": "#FFFFFF",
"validDomains": [
"3821-68-69-235-13.ngrok.io"
]
}
Despite everything mentioned in the documentation, the following is required otherwise you'll get this error. This fixed things for me.
microsoftTeams.settings.registerOnSaveHandler(saveEvent => {
microsoftTeams.settings.setSettings({
contentUrl: "https://xxxxxx.ngrok.io/teams/connector"
});
saveEvent.notifySuccess();
});
The documentation states that registering a save handler is optional and Teams will handle notify success if it's not declared. WRONG. You must register a save handler.
The documentation does not state that setSettings is required. WRONG. You must set settings or else you will receive this error.
The documentation does not state that you must save a contentURL. WRONG. You must set content URL in the setSettings. You can apparently omit other things when setting your settings, but not content URL.
The documentation does not specifically mention it, but the contentURL must comply with your validURLs in your manifest. If it does not, you'll also see this error.

Disable webview2 download progress bar in tauri application

I am converting a single page front-end website to desktop application using tauri toolchain. When I download an image or any other file in the application, it displays a download progress bar in the top right corner. I have to disable the progress bar. When I searched how to disable it in this webview2 documentation, it suggested that I can set the CoreWebView2DownloadStartingEventArgs.Handled property to true which will hide the download progress dialog. But I can't find how to set that property in my tauri application source code. I have included my project directory and the all the codes that I have included so far. It will be helpful for me if someone could explain how to set that property to true so that I can hide how to hide the progress bar in my application.
Project Folder: https://drive.google.com/drive/folders/1rT_uaH6Ki_B2Hpud0SsI9ZUNZMZpmUWD?usp=sharing
HTML File:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<img src="https://cdn.pixabay.com/photo/2014/02/27/16/10/flowers-276014_960_720.jpg" alt="W3Schools" width="500">
<a href="https://cdn.pixabay.com/photo/2014/02/27/16/10/flowers-276014_960_720.jpg" download="image.jpg">
<button type="button">Download</button>
</a>
</body>
</html>
RUST main file:
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
tauri.conf configuration file:
{
"build": {
"beforeBuildCommand": "",
"beforeDevCommand": "",
"devPath": "../assets",
"distDir": "../assets"
},
"package": {
"productName": "test",
"version": "0.1.0"
},
"tauri": {
"allowlist": {
"all": true
},
"bundle": {
"active": true,
"category": "DeveloperTool",
"copyright": "",
"deb": {
"depends": []
},
"externalBin": [],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128#2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"identifier": "com.tauri.dev",
"longDescription": "",
"macOS": {
"entitlements": null,
"exceptionDomain": "",
"frameworks": [],
"providerShortName": null,
"signingIdentity": null
},
"resources": [],
"shortDescription": "",
"targets": "all",
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"security": {
"csp": null
},
"updater": {
"active": false
},
"windows": [
{
"fullscreen": false,
"height": 600,
"resizable": true,
"title": "Test",
"width": 800
}
]
}
}
Got my answer here
I added the following dependencies to my Cargo.toml file
webview2-com = "0.19"
windows = "0.39"
Then in my main.rs, I added a setup hook to the Builder with the following content
#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]
use tauri::Manager;
use webview2_com::{
DownloadStartingEventHandler, Microsoft::Web::WebView2::Win32::ICoreWebView2_4,
};
use windows::{core::Interface, Win32::System::WinRT::EventRegistrationToken};
fn main() {
tauri::Builder::default()
.setup(|app| {
let window = app.get_window("main").unwrap();
#[cfg(windows)]
window.with_webview(|webview| unsafe {
let mut _token = EventRegistrationToken::default();
let core = webview
.controller()
.CoreWebView2()
.unwrap()
.cast::<ICoreWebView2_4>()
.unwrap();
let handler =
DownloadStartingEventHandler::create(Box::new(move |_, args| {
if let Some(args) = args {
// i don't know how safe that unwrap is, so you may wanna handle errors
// or just ignore them with `let _ = args.SetHandled(true);`
args.SetHandled(true).unwrap();
}
Ok(())
}));
let _ = core.add_DownloadStarting(&handler, &mut _token);
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

Popup in Firefox WebExtension only loading first javascript file

I'm loading a popup via the "browser_action" option in manifest.json. The HTML file loads, and the FIRST script tag I declare loads, but the other two js files after it doesn't. The javascript is loaded at the bottom of the file, like so:
<script type="application/x-javascript" src="const.js"/>
<script type="application/x-javascript" src="core.js"/>
<script type="application/x-javascript" src="options.js"/>
and the manifest looks like this:
{
"manifest_version": 2,
"name": "myExtension",
"version": "1.1",
"description": "myExtension",
"icons": {
"32": "chrome/skin/myExtension.png"
},
"permissions": [
"activeTab"
],
"browser_action": {
"default_icon": "chrome/icons/default/myExtension.ico",
"default_title": "myExtension",
"default_popup": "chrome/content/options.html"
}
}

Content script not running

I need to run a content script attached to a specific HTML page that appears when an error occurs. The webextension is an embedded extension at the moment. The files structure is as follows:
- SDK extension [directory]
- webextension [directory]
- main.js
- data [directory]
- error.html
- error-script.js
Everything runs well except that when I click on the button which should fire the content script, nothing happens. I tried several format for the content script file path in the manifest.js "js": ["webextension/data/error-script.js"] but nothing changed.
EDIT:
The path for the error.html when an error occurs contains some automatically generated prefix which does not reflect the actual path:
moz-extension://7c92a8c2-219d-4233-a973-c51032e2a375/data/error.html
Here is a simple example code:
1) manifest.json:
{
"manifest_version": 2,
"name": "example",
"version": "1.0",
"description": "No description.",
"background": {
"scripts": ["main.js","error.js"]
},
"content_scripts": [
{
"matches": ["*://*/error.html"],
"js": ["webextension/data/error-script.js"]
}
],
"permissions": [
"<all_urls>",
"activeTab",
"tabs",
"storage",
"webRequest"
],
"browser_action": {
"default_icon": {
"64": "icons/myicon.png"
},
"default_title": "example"
},
"hasEmbeddedWebExtension": true
}
2) HTML page error.html:
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
Test.
<input type="button" class="error-button" id="error-button" value="error">
</body>
</html>
3) A content script error-script.js:
var button = document.getElementById("error-button");
button.addEventListener("click",showAlert);
function showAlert()
{
alert("Error");
}//end function.
4) A background script: error.js:
var target = "<all_urls>";
function logError(responseDetails) {
errorTab=responseDetails.tabId;
console.log("response tab: "+errorTab);
browser.tabs.update(errorTab,{url: "data/error.html"});
}//end function
browser.webRequest.onErrorOccurred.addListener(
logError,
{urls: [target],
types: ["main_frame"]}
);

Use of aJax in extension default_popup?

Can I somehow use aJax in my Google Chrome Extension "default_popup".
I have tried the following...
manifest.json:
{
"name": "My extension",
"manifest_version": 2,
"version": "1.0",
"permissions": [
"tabs", "http://*/*"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["jquery-1.8.3.min.js", "content.js"],
"run_at": "document_end"
}
]
}
popup.html:
<html>
<body>
<script>
$.ajax({
type: "GET",
url: "http://www.mysite.com/api.php"
}).done(function(response) {
alert("work");
}).fail(function(response) {
alert("doesn't work");
});
</script>
</body>
</html>
Does anyone have any ideas how to do this?
It's possible, but you'll most likely have to use JSONP. You can use what you already have as a basis, so it shouldn't require much refactoring.

Resources