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

251
Views
How to use web3.js in Chrome extension's background.js?

I'm attempting to use web3.js in a Chrome extension's background.js file (manifest v3) like so:

// background.js

const Web3 = require('web3')
const web3 = new Web3("https://api.avax.network/ext/bc/C/rpc")

var abi = [
    {
      "constant": true,
      "inputs": [],
      "name": "owner",
      "outputs": [
        {
          "name": "",
          "type": "address"
        }
      ],
      "payable": false,
      "type": "function"
    },
    {
      "inputs": [],
      "payable": false,
      "type": "constructor"
    }
  ];


var MyContract = web3.eth.contract(abi);

But I instantly receive the error that "window is not defined". I understand that Chrome background scripts don't have access to window, but I don't understand why attempting to instantiate web3 requires access to window.

Screenshot of extension error.

I'm using webpack to bundle web3.js with background.js.

My goal is to make read calls to a contract from background.js, and figured web3.js was the easiest method.

about 4 years ago · Santiago Trujillo
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!