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

161
Views
window.print() not working in browser extension

I am trying to make a print browser extension using window.print() but it is not working, whereas as a separate HTML file it is working.

Below are popup.js and print.html

document.getElementById("m").addEventListener("click", myFunction);

function myFunction() {
  window.print();
}
<!DOCTYPE html>
<html>

<body>
  <h2>The window.print() Method</h2>
  <button id="m"> click me </button>
</body>
<script src="popup.js">
</script>

</html>

manifest file is

{
  "manifest_version": 2,
  "name": "print",
  "version": "0.10002",
  "content_scripts": [{
    "matches": ["<all_urls>"],
    "js": [
      "popup.js",
      "content.bundle.js"
    ],
    "run_at": "document_idle",
    "matches": ["https://*/*"]
  }],
  "browser_action": {
    "default_popup": "print.html"
  },
  "background": {
    "scripts": [
      "background.bundle.js",
      "background.js"
    ]
  },
  "permissions": [
    "storage",
    "https://*/*"
  ]
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try this:

Below are script.js and file.html

 document.getElementById("btn").onclick = () => window.print();
<!DOCTYPE html>
<html>
<body>

<p>Click the button to print the current page.</p>

<button id = "btn" >Print this page</button>

<script src = "script.js" ></script>

</body>
</html>

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!