Reputation: 71
iam trying to build an chrome extension that do actions on site, the site have his API , for example if you click on edit link in site, in backgroung its send an API command like this App.Cases.edit(Casenumber)
when iam calling this line via chrome extension send script API i get an error, the error said that its anonymous function.
So what i did is i found the path that lead to the element that trigger the click. as you can see in code, and now i get an Uncaught Error: NotFoundError: DOM Exception 8 Any one have an idea how to handle this issue? or maybe even more simple how to get acess to the site API.
here is the code , this is the JS file
$(document).ready(function()
{
$('#btn1').click(function(){
chrome.tabs.executeScript(null,{file:"jquery-1.10.1.min.js"},function() {
chrome.tabs.executeScript(null,{code:" $('#row-37416').children().eq(3).children().eq(1).click(); "});
});
});
this is the html file:
<html>
<head>
<link href="style.css" rel="stylesheet" type="text/css" />
<script src='jquery-1.10.1.min.js'></script>
<script src='alert.js'></script>
<script src='contentscript.js'></script>
</head>
<body>
<h1 id = "title">Extensions</h1>
<input type = "button" value ="Find And Replace" id="btn1" />
<div id="content">
</div>
</body>
</html>
this is the manifest file:
{
"name": "TEST",
"version": "1.0",
"manifest_version": 2,
"description": "jonathan",
"content_scripts": [
{
"matches": [ "http://*/*", "https://*/*"],
"js": ["jquery-1.10.1.min.js", "alert.js","contentscript.js"]
}
],
"permissions": [
"tabs", "http://*/*" , "https://*/*"
],
"browser_action":{
"default_icon": "icon.png",
"default_popup": "popup.html"
}
}
Upvotes: 1
Views: 2945
Reputation: 1798
Use "trigger()" to trigger the click instead of ".click()". See here:
http://api.jquery.com/trigger/
Upvotes: 1