0

I'm trying to create a chrome extension that simulates .mouseover() event.

Here is a sample of the page that i'm trying to simulate that event.

<div class="hand card-stack" aria-disabled="false">
...
<div id="card-c181" class="card face-up ui-draggable">
    <div class="face"></div>
    <div class="back"></div>
</div>
...
</div>

when i put the mouse on those divs the class value changes and i'm trying to write a script to detect the change of the class name automatically and my best idea was to simulate .mouseover()

so before i write the actual inject code i test them in chrome console and they work just fine but when i inject them they don't...

Here is my inject.js

$(document).ready(function(){
$(main);    
});
function main()
{
  x = $('.card.face-up.ui-draggable').mouseover();
  alert("DONE");
}

Manifest.json

{
  "name": "Testing",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Simulating mouseover",
  "homepage_url": "http://example.com",
  "background": {
    "scripts": ["background.js", "jquery-1.12.4.js"] ,
    "persistent": true
  },
  "browser_action": {
    "default_title": "Inject!"
  },
  "content_scripts": [{
      "js": ["jquery-1.12.4.js"],
      "matches": ["https://*/*"]
  }],
  "permissions": [
    "https://*/*",
    "http://*/*",
    "tabs"
  ]
}

So when i click on my extension button it just alerts and the mouseover don't work.. but in chrome console it works. i've tried .mouseenter(), .trigger("mouseover"),.on` nothing worked in inject.js but in chrome console they works.

Mohamed Horani
  • 544
  • 3
  • 9
  • 23
  • The reason it works in the console is that `$` refers to the page's jQuery. To access it your code should run in page context: [Insert code into the page context using a content script](//stackoverflow.com/a/9517879) – wOxxOm Sep 10 '17 at 13:40
  • @wOxxOm Thanks :) it finally worked – Mohamed Horani Sep 10 '17 at 13:55
  • Possible duplicate of [Insert code into the page context using a content script](https://stackoverflow.com/questions/9515704/insert-code-into-the-page-context-using-a-content-script) – Makyen Sep 12 '17 at 03:23

0 Answers0