Is it possible to insert a JavaScript module into a webpage using a Firefox web extension?

When attempting to load a script in my extension's content script, I encounter an issue:

let s = document.createElement("script");
s.setAttribute("async", "");
s.setAttribute("type", "module");
s.setAttribute("src", "https://gamergirlandco.github.io/some_script.js");
s.setAttribute("crossorigin", "anonymous")
document.body.appendChild(s)

An error is thrown stating:

WebExtension content scripts may only load modules with moz-extension URLs and not: “https://gamergirlandco.github.io/some_script.js”.

I attempted to resolve this by adding *://gamergirlandco.github.io/* to the permissions array in manifest.json, but it did not solve the problem.

Any assistance on how to address this would be greatly appreciated.

Answer №1

  • Before injecting any script, remember that the webpage's CSP (Content Security Policy) could prevent it from being executed
  • Always obtain permission from the website before attempting to inject any scripts

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

jQuery's display function is being obstructed by a lengthy operation

$('#someid').show(); someLongRunningFunction(); This snippet indicates that the element with id $('#someid') will be displayed only after the function someLongRunningFunction completes its execution. Is there a possible way to modify t ...

Spinning a tetrahedron in three.js along the proper axis

I need to showcase a rotating tetrahedron in an animated HTML5 graphic, using three.js. Despite creating the object, it appears upside down instead of resting on the ground with one surface facing up, like in this reference image: The current rotation co ...

Utilize Angular, PHP, and MySQL to add data to database encountering error

Working with a controller to fetch records from a database table and bind them to textfields for insertion into another table. However, upon submission, encountering the following error: TypeError: Cannot read property 'resp_fname' of undefined ...

The Bootstrap navigation menu is functioning properly when opening, but has an issue when attempting

Creating a mirrored version of an HTML file using NuxtJS, I've included the following code snippet in the Navbar component for my NuxtJS project. <template> <section id="navigation-menu" class="menu menu3 cid-sLhoPz7Ycg" ...

Utilize an Ajax request to send an array to JavaScript code

I have a datepicker set up and I need to update a MySQL database by making specific dates unavailable when it is clicked. How can I pass an array into my JavaScript code at the "AJAX CALL CODE NEEDS TO GO HERE" section? Below is my JavaScript code for the ...

Utilizing NodeJS and Mongoose to retrieve a specific variable and return its

I appreciate your time and assistance in advance. I've been struggling with something that seems like it should be easy but it's driving me crazy. My objective is to assign the result of a function to a variable that I can later use in a POST r ...

Is there a way to extract the HTML source code of a website using jQuery or JavaScript similar to PHP's file_get_contents function?

Can this be achieved without a server? $.get("http://xxxxx.com", function (data) { alert(data); }); I have tried the above code but it seems to not display any output. ...

AngularJS has the ability to reverse progress bars

I have recently developed a small AngularJS application that includes a dynamic data table utilizing ng-repeat. The table reflects real-time changes in the data, with rows being updated, added, and removed through web socket communication. Each row in the ...

Angular.js Form Submission Results in Error 405: POST Method is Not Permitted

Every time I attempt to submit my form, I come across a 405 error. Here is the code snippet from my controller: 'use strict'; angular. module('myApp'). component('zipPopup', { templateUrl: 'zip-popup/zip ...

Ever since I switched to a different monitor, my Javascript has suddenly stopped functioning

I'm encountering an issue where my JS stops working every time I switch displays within a single HTML file. I've attempted to replace the HTML onclick call with a JavaScript function, but the problem persists. Update: Apologies for the unclear e ...

Tips for sending a reply following several requests to a third-party API in Node.js

I've been tackling a project that involves making numerous requests to a third-party API and then sending an array of the received data back to the client. Since the requests to the API are asynchronous, I'm encountering an issue where if I place ...

Angular 6: Simplify Your Navigation with Step Navigation

Can someone please assist me with configuring a navigation step? I tried using viewchild without success and also attempted to create a function with an index++ for three components on the same page. However, I am unable to achieve the desired outcome. Any ...

Issues encountered with AngularJS directive binding inner content not functioning as expected

I am currently developing a feature toggle directive, which requires a check to be performed in order to display content if the check is successful. I want the directive to replace itself with its content without creating a new child scope (so I'm try ...

What is the best way to reverse an EJS forEach loop?

Here is my ejs code to display images and names from my database. How can I reverse the array order to show the images and names in reversed order? <% posts.reverse().forEach(function(post){ %> <div class="col-md-3 col-sm-6"> ...

I am puzzled by the presence of the 'x' value in the JSON object when creating a column chart using CanvasJS. Its origin remains unknown to me

I'm exploring the use of canvasjs and I have a test code snippet that I'm working with: 9 $con = pg_connect("host=localhost port=5432 dbname=testdb user=postgres") or die ("Could not connect to server\n"); 10 $query ="SELECT id as label, ...

Introducing the feature of adding an Opacity Slider specifically designed for the chosen object

I am trying to implement an opacity slider to adjust the visibility of selected objects based on the slider's position (100 indicates complete visibility). I am using fabric.js/master/dist/fabric.js and jQuery 3.3.1. Could you please help me identify ...

Generate dropdown options dynamically using AJAX from an array

My function to send email addresses to ajax only works for a single email address, not multiple. How can I modify it to work for more email addresses? onclick='show_general_email_modal(\"$emails\");' When executed, the following is se ...

Creating files using the constructor in Internet Explorer and Safari

Unfortunately, the File() constructor is not supported in IE and Safari. You can check on CanIUse for more information. I'm wondering if there's a workaround for this limitation in Angular/JavaScript? var file = new File(byteArrays, tempfilenam ...

Trouble with importing React JSX from a separate file when working with Typescript

This problem bears some resemblance to How to import React JSX correctly from a separate file in Typescript 1.6. Everything seems to be working smoothly when all the code is contained within a single file. However, as soon as I move the component to anoth ...

Determine the cost through a command line application

Recently, I came across an intriguing exercise that challenges the creation of a command line program to calculate the total price of an order. The task involves summing up the price of each product in the order multiplied by the quantity of each item, wit ...