Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Refused to load the script 'https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js' because it violates the following Content Security Policy

I was working on a chrome browser extension. When I tried to connect firebase with the web app in 2 possible ways none is working.

  1. using "npm install firebase" When I tried this command to install firebase into my project folder and written a fireConn.js file along with the configuration I got from firebase project created online.
import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';

The error which I got is

Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../".
  1. using the https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js url to get connected with the firebase
import {initializeApp} from "https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js";
import {getFirestore} from "https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js";

As my project is a chrome extension, I have a manifest.json file which is in the following format:

{
  "name": "xxx",
  "manifest_version": 3,
  "version": "1.0",
  "permissions": ["cookies","tabs"],
  "host_permissions": ["<all_urls>"],
  "action": {
    "default_popup": "popup.html"
  },
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'",
    "sandbox": "sandbox allow-scripts; script-src 'self' 'https://apis.google.com/' 'https://www.gstatic.com/' 'https://*.firebaseio.com' 'https://www.googleapis.com' 'https://ajax.googleapis.com'; object-src 'self'"
  }
}

The error which I was getting is:(something went wrong with the content_security_policy)

Refused to load the script 'https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

First, modify the imports as below:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js";
import { getFirestore, collection, getDocs } from "https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js";

You can find more information regarding it from the documentation. Since you are using a module bundler, needs type="module" to be added to it. The correct format should be:

<script type="module" src="........”></script>

Please note: src depends on how you set the path.

You may also refer to the video Getting started with Firebase for the web – Firebase Fundamentals. Also, the Cannot connect to Firebase,Uncaught Error in Firebase might add to it.

about 4 years ago · Juan Pablo Isaza Report

0

You should replace https://www.gstatic.com/ references in other files

in firebase-firestore.js

import { _registerComponent, registerVersion, _getProvider, getApp, _removeServiceInstance, SDK_VERSION } from 'https://www.gstatic.com/firebasejs/9.6.8/firebase-app.js';

change to line

import { _registerComponent, registerVersion, _getProvider, getApp, _removeServiceInstance, SDK_VERSION } from './firebase-app.js'; 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!