I am new to Chrome extensions and trying to create a simple code to insert some text into a html input field or text area value from a dropdown menu or right clicking.
But receiving the following error.
Error in event handler: TypeError: Cannot set property 'value' of null
However this works ok if i use the console , what am I missing here?
msg_cnt_cnt is the ID of the HTML of the box and the only box on the page
Here is my code :script.js
function past_to_box() {
var text = 'Hello world';
document.getElementById("msg_cnt_cnt").value = text;
}
chrome.contextMenus.create({
title: "Dispatched",
contexts:["all"],
onclick: past_to_box
});
manifest
{
"name": "Getting Started Example",
"version": "1.0",
"description": "Build an Extension!",
"permissions": ["activeTab", "declarativeContent", "storage","tabs","contextMenus"],
"background": {
"scripts": ["script.js"]
},
"manifest_version": 2
}