Develop a chrome extension to capture clicks using chrome extension api - google-chrome-extension

I am trying to develop a chrome extension which can capture clicks using chrome extension APIs not by JavaScript.

If you want to capture the 'click' events in chrome extension, this answer might help you from the question - How may I get the element attributes (text, id, class and so on..) of the current tab, out of a mouse click, from a chrome extension?
In your content.js, write the following code-
$(window).click(function(event) {
console.log("Click event: ", event);
});
Content scripts are files that run in the context of web pages. By using the standard Document Object Model (DOM), they are able to read details of the web pages the browser visits, make changes to them and pass information to their parent extension.

Related

Capture a mouse-up event with a chrome extension

Is it possible to capture a mouse-up event on any given page when using a chrome extension? I know that the API allows you to interact with the DOM, and I'd like to recreate the behavior of the standard onMouseUp event, but I'm not quite sure if it can be done when used through a chrome extension

Chrome extension: How to do not lose state of my extension when user changes/reloads the page

I'm currently developing an extension that comes in different parts:
- background script (Chrome background.js
- content script (Chrome content-script.js)
- popup script (popup.js and loaded from the iFrame)
- iframe.html (iframe to be loaded when user activate the extension)
It works great except that I lose all the settings/context (used in the popup script to display info in the iframe) when the user change of page or reload the page in the tab.
Technically I want to isolate the extension per tab (each tab can have its own config) but when a user navigate in a same tab the context should be kept.
Question is: what is the best way to achieve that?
I'm thinking about persisting all the context in the content script and reload it when the event chrome.tabs.onUpdated is fired. Is it the right approach?
I recommend you to read about chrome.storage. You can store data there, both background and content script have access to it.
And probably you will need chrome.runtime.sendMessage and chrome.runtime.onMessage to have conversation between background and content. Each time content script runs in a tab it can request background whether this tab have some existing data or not.

Can Chrome Extension’s new options_ui trigger a page action?

I’ve been placing a page action on the options page of my Chrome extension. options.js calls chrome.runtime.connect({"name":"someName"}), and background.js has
chrome.runtime.onConnect.addListener(function(port) {
chrome.pageAction.show(port.sender.tab.id);
});
Unfortunately, in the new options_ui with the recommended default (and someday mandatory) "open_in_tab":false, the Sender's tab won't be set. Is there a way to get the tab id in order to show the page action?
I could use tabs.query to get the chrome://extensions/ tab, but that requires the tabs permission, which I currently don’t need. Active tab seems like it would work, but it doesn’t provide the tab id and isn’t enabled by opening an option dialog (source).
(Why do I want the page action on my options page? The extension works with a website that is only available ~7-10 weeks per year. I’d like my users to be able to interact with the extension the rest of the time, so that they can get used to the process. But I don’t want to adjust the displayed extension permissions just to do so. I can accomplish this by having the options page pretend to be the website in question.)

How to open a new tab in a chrome extension and show data

I have a chrome extension which allows the user to perform actions and build up data. How can I get my chrome extension to open a new tab to allow my user to interact with the data they've accumulated? I could build a separate web app service where I pass the users data to. I currently persist the users data in local storage but I want a way for them to view/edit that data.
Not sure what exactly to google to get a chrome extensions to launch a new page under it's url...
Edit:
Ideally I'd like for my user to press a button from the popup.html popup to open up the new tab, if possible.
I got it to work, basically from the popup.html page I can make this javascript call,
chrome.tabs.create({url: chrome.extension.getURL('dashboard.html')})
where 'dashboard.html' is file belonging to my chrome extension.

Accessing browser events in chrome extension - DOM events in chrome extension

I am writing a chrome plugin in which I would like to receive events such as "load", "unload" of window and page. However, I'm not getting any concrete clue to start with.
Can anyone tell me how to capture DOM event in plugin?
Does Chrome support this feature?
Thank you.
You would need Content Scripts and you just add normal browser events to the JavaScript you inject as you stated in your question. Every page will have that content script and it will listen on those events.

Resources