I would like to interact with the DOM of my current page when i click on an event in a contextualMenu from ChromeExtension.
There is my code :
manifest.json
{
"name": "jQuery DOM",
"version": "1",
"permissions":[
"http://*/",
"contextMenus"
],
"description": "Manipulate the DOM when the page is done loading",
"background": {
"scripts": ["sample.js", "jquery.min.js"]},
"browser_action": {
"name": "Manipulate DOM",
"icons": ["icon.png"],
"default_icon": "icon.png"
},
"content_scripts": [ {
"js": [ "jquery.min.js", "background.js" ],
"matches": [ "http://*/*", "https://*/*"]
}],
"manifest_version": 2
}
sample.js
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// A generic onclick callback function.
function editOnClick(info, tab) {
alert($("body").html());
}
// Create a parent item and two children.
var parent = chrome.contextMenus.create({"title": "Therefore"});
var child1 = chrome.contextMenus.create(
{"title": "Éditer", "parentId": parent, "onclick": editOnClick});
When i try this, i get with my alert box:
<script src="sample.js"></script>
<script src="jquery.min.js"></script>
But with $("body").append('TEST')
in my background.js, i can interact directly with the DOM of my currently page.
I don't know why i can't from a contextualMenu.