Prompt not displaying

Hi, I am just learning so I created this very basic plugin.
When you right-click on a tab, it has a new item called “Prompt for Name” which is supposed to call a simple prompt. I loaded the plugin in about:debugging and ran it. The menu item comes up when I right click the tab, but nothing happens when I click on it. Here is the code:

Manifest:
{
“manifest_version”: 2,
“name”: “Page Title Changer”,
“version”: “1.0”,

"description": "Prompts the user to change the page title when they right-click on the page.",

"permissions": [
  "contextMenus",
  "tabs"
],

"background": {
  "scripts": ["background.js"]
}

}

background.js

function promptForName(info, tab) {
let name = prompt(“Please enter your name:”);
// do something with the user’s name
}

browser.contextMenus.create({
id: “prompt-for-name”,
title: “Prompt for Name”,
contexts: [“tab”]
});

browser.contextMenus.onClicked.addListener(promptForName);

The background script doesn’t have access to the page. To do what you are trying to do, you would need a content script and would likely need to pass a message from the content script to the background script.

1 Like

bonus tip - when pasting code here, put triple backticks (```) on the line above and below the code to activate formatting