Skip to content
Advertisement

Simulated Click in Chrome Extension

I am making a Chrome extension. One part of this extension needs to be able to simulate a click in order to activate the onClick events on the page. Here is the code from the background script:

JavaScript

Here is the error message that I am getting from Chrome’s JavaScript debugging:

JavaScript

I am guessing that it is something to do with the permissions in the manifest file… Right now I only have permissions to “tabs”. Is there some other permissions I need to activate in order to simulate the click and not get an error? Oh and I am trying to make this capable with version 2 manifest protocol.

Advertisement

Answer

Script execution environments are different for extension and page.

Use chrome.tabs.executeScript

For example, to paste some text to Google search field

File: manifest.json

JavaScript

File: background.js

JavaScript

In manifest file there is need permission to host ("http://*/*").

But if question was strictly on JavaScript click event, look here How to simulate a click with JavaScript?

Advertisement