0

I am trying to edit text using js in a Chrome extension using designmode not working. It works in the console but here is there any additional change I need to make to make this work for the Chrome extension

all the code below - manifest.json --

{
"manifest_version" : 2,
"name" : "changer",
"version" : "1.0",
"description" : "chnage it",
"icons" : {
    "128" : "icon_128.png",
    "16" : "icon.png"
},
"browser_action" : {
    "default_icon" : "icon.png",
    "default_popup" : "popup.html"
},
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}

js code -

document.getElementById("btn").addEventListener("click", change);
document.getElementById("btnclose").addEventListener("click", close);

function change (){
    document.designMode = 'on'
}

function close (){
    document.designMode = 'off'
}

html -

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
    <title>Document</title>
</head>
<body>
    <div class="main">
        <div class="heading">
            Change text on the web 
        </div>
        <div class="button">
            <button id="btn">Turn ON</button>
            
            <button id="btnclose">Turn OFF</button>
        </div>
    </div>
</body>
<script src="script.js"></script>
</html>

I am trying to edit the text on the web but it is not working it works in the console I also tried

document.contentEditable=true

but it also didn't work

Nimantha
  • 5,793
  • 5
  • 23
  • 56
Aditya
  • 109
  • 1
  • 1
  • 6

0 Answers0