How to make a sticky popup for chrome extension

Viewed 765

I am new to chrome extension. And I need to create an extension That Appends the external class to the selected tag.

ex:- page

<h1>extension</h1> need to add an external class to the DOM when this tag mouse is clicked on the element. (should not be an empty element)

For that, I am creating a chrome extension. In order to do this, I need to have a fixed popup or Canvas. Like the CSS Selector use.

I want my popup.html to close only when I click on the close button, not when I click on the element of the page. I can not find a way to stick the popup. it is closed every time I clicked on the web page.

this is my manifest code

{
"manifest_version": 2,
"name":"Spider_Extension",
"version":"1.0",
"permissions": [
    "tabs"
  ],
"content_scripts":[{
    "matches":[
        "<all_urls>"
    ],
    "js":["Content.js"]
}],

"background": {
    "scripts": ["background.js"]        
  },
"browser_action":{
    "default_icon":"get_started16.png"
 }
}

this is my background.js



function button_clicked(tab){
let msg={
   txt:"hello"

}
console.log(tab)
chrome.tabs.sendMessage(tab.id,msg);



}

this is my popup.html

<html>
​
<head>
   <title>Spider extension</title>
   <link rel="stylesheet" href="styles.css">
</head>
​
<body>
​
   <label for="cars">Select Level:</label>
   <select id="levels">
       <option value="l1">L1</option>
       <option value="l2">L2</option>
       <option value="l3">L3</option>
       <option value="l4">L4</option>
   </select>
   <br>
   <button id="addLevel" style="margin:5px;">Add level</button>
   <br>
   <button id="break" style="margin:5px;">Break</button>
   <br>
   <button id="deselect" style="margin:5px;">Deselect</button>
   <br>
​
   <button id="nd__close">X</button>
​
   <script src="popup.js"></script>
</body>
​
</html>

can anyone guide me for a solution ?

thank you in advance

1 Answers

I don't think popups are intended to be used like this and it won't be possible with the traditional popup structure. You would have to go the ugly way and injecting your popup content to the page (many popular extensions do this actually). The better way to approach this instead would be to use context menus: https://developer.chrome.com/apps/contextMenus You could right click on the element you want to select, like how ublock origin does: enter image description here

Related