Send data from chrome extension to website/web application - google-chrome

I have developed a chrome extension, now I want to send some data from my extension to my website. I don't want to use backend as in this example: Send Data from chrome extension to Node.js
I want some way I can get the data in my frontend, my website doesn't have a backend. Your help is appreciated.

As commented by wOxxOm by using content script as stated here: How to access the webpage DOM rather than the extension page DOM? we can access the DOM of our webpage and make changes and send data to it from our chrome extension.

Related

Can the manifest file be dynamic in Chrome Apps?

I am writing a Chrome App that communicate with a web page. For that I have added something similar in my manifest file.
"externally_connectable": {
"matches": ["*://*.example.com/*"]
}
But the "example.com" has to be dynamic as individual customers has their one web server.
Is there any possibility, user(who install the app) can change the externally_connectable site/s.
There is an alternative way a web page can communicate with extension through content script. This approach can be used if both web page and extension are done by you.
E.g.
web page <--> content script of extension <--> background script of
extension <--> native application
For web page to content script of extension communication use window.postMessage and window.addEventListener
For Google Chrome browser,
For content script of extension to background script of extension communication use chrome.runtime.sendMessage and chrome.runtime.onMessage.addListener
For background script of extension to native application communication use chrome.runtime.sendNativeMessage
Please make sure your code has necessary security in place.
As far as I know the "externally_connectable" is the only official way to send messages (With data) from a web page as mentioned here
This requires a predefined values for every single domain. But what if you want to make only one extension to accept messages from any web page?
If you just want to notify the other side about some thing, you can use the native JS Event dispatching it on the document from one side and listening to it at document also from the other side as the document is shared between the extension content script pages and the web page.
You can't use JS CustomEvent to send data as every time you send data, you receive it empty as a result of sandbox effect of any extension.
If you want to share data so the only workaround I know so far - after spending about one month developing an extension - is to have a combination between some sort of a storage and the JS native Event mechanism.
The solution in steps (suppose you need the web page to send some data to the extension):
Make an event on document from the web page.
Save the data temporarily inside any storage technology you prefer
(localStorage, the DOM itself, or what ever..)
Receive the event at the other side (extension) by listening on the
document.
Read data and remove it.
Hope this helps someone or open a door for a discussion on a better way doing this.

Access webpage's localStorage from a Chrome extension

i'm developing a chrome extension which requires to get the values(to plugin) from local storage where values are stored by some other webpages that were created by me
In short: Access a webpage's localStorage from a Chrome extension script
I just tested it, and if you access localStorage from the context of a content script, you get the webpage's localStorage. So, nothing special is required besides injecting a content script into the webpage you need.
To communicate the value from the content script you can use Messaging API, and you can use chrome.storage.local API to save data in a way that's accessible from both the content script and the background page.

Interacting with firefox using an external program

I am looking for a way to interact with a web page and enter data to certain fields in it using an external program that interact with Firefox (or Chromium) web browser. The best I could find is the console commands for the browser, but they only let you go to a certain URL and not interact with the pages' content. I have also tried looking for some extension to do the job but I could not find any. Any suggestions?
You could create Chrome extension that communicates with your application via Chrome Native Messaging API: https://developer.chrome.com/extensions/messaging.html#native-messaging
Take a look at Selenium and the tools mentioned at Selenium alternatives?.

Google Chrome Extension for interacting with a web application

hope somebody understand and can maybe explain me my idea.
My Goal:
I would like that the user can use my web application, but the requests for parsing urls, etc will not run on my server, but
are processed on the client side via the browser.
My theoretical example:
There is a web application the user need to login.
If the user is logged in, he can paste ten urls into a textinput box and than push a button.
Then a ajax request is made to the server and the urls are parsed and the site informations from the parsed urls comes back as json to display it in the frontend.
Ok now my real question.
Is it possible to create a Google Chrome Extension that catches the Post request from the textarea, and send the urls to the
background.js. than the background.js should request this urls via javascript xmlhttprequest to bypass the cross-orgin restriction.

How to open links using a chrome app? (Similar to how Android prompts you on what app you want to use to handle certain URLs)

I have a chrome app which displays data pulled from website A.
If a user has the app installed, and is on website A, how can I make the chrome app detect that the user is on website A and then prompt the user to open website A in the chrome app?
I'm trying to mimic how Android does this if you try to open a Google Play Store URL for example.
Thanks in advance,
Dimitry
Your app needs to define a webRequest (part of permissions) in the manifest file. You might use the blocking response to then handle all the stuff yourself.