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

179
Views
navigator.clipboard.writeText() fails within an unpacked Edge or Chrome extension

My goal is to make an extension for myself(and hopefully others) that adds a more left-handed user friendly copy link address keybind(Y or A) for Microsoft Edge. But as stated navigator.clipboard.writeText() fails without any meaningful indicator to the problem and nothing is copied to system clipboard.

Environment:

  • Windows 10
  • Chrome 97.0.4692.71
  • Edge 97.0.1072.55

The JS code:

const CONTEXT_MENU_ID = "MY_COPY_LINK";

async function copyLink(info, tab) {
  if (info.menuItemId !== CONTEXT_MENU_ID) {
    return;
  }
  var urlToCopy = info.linkUrl;
  console.log(urlToCopy + " was copied.");
  
  if(navigator.clipboard) {
    navigator.clipboard.writeText(urlToCopy).then(function() {
      /* clipboard successfully set */
      console.log("success");
    }, function() {
      /* clipboard write failed */
      console.log("failed");
    });
  }
  else {
      console.log("clipboard undefined");
  }
}

chrome.contextMenus.create({
  title: "Cop&y Link Address", 
  contexts:["link"], 
  id: CONTEXT_MENU_ID
});

chrome.contextMenus.onClicked.addListener(copyLink)

Manifest file:

{
    "manifest_version": 2,
    "name": "copylinkaddress",
    "version": "1",
    
    "permissions": ["contextMenus","clipboardWrite"],
    "background": {
        "scripts": ["background.js"],
        "persistent": true
    }
}

I've tried using write() only with a text/plain ClipboardItem but same result, it just fails.

about 4 years ago · Juan Pablo Isaza
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!