Can the manifest file be dynamic in Chrome Apps? - google-chrome

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.

Related

Send data from chrome extension to website/web application

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.

Is it possible to access web viewer content in Filemaker Pro?

I am developing Filemaker application that uses web viewer.
I need to access to DOM or Window object inside web viewer control so that I can send some messages(or trigger predefined events) to web page from Filemaker.
So the goal is to make web page inside web viewer control get some data that Filemaker sends at any time. Web page is a local html file of which URL starts with file:///.
Is it possible to do this or is there another way to accomplish this task?
It's much easier to send a message from the web viewer to FileMaker using the fmp url protocol (which you can use to e.g. call a script in FileMaker from Javascript).
You can't send a message directly to the web viewer from FileMaker. Your best bet is to set a variable on a service somewhere and have the web viewer poll that service to see if the value changes.
"This task" is not well-defined, IMHO. What exactly are "messages" or "predefined events"? You certainly can use the Set Web Viewer script step to make the web viewer load another URL at any time you wish to.
Note also that you can use Data URI to load data into the web-viewer directly, without requiring an external HTML document.

How Chrome App (not Extension) can read DOM element of page hosting app install button

For my Chrome App, I followed Using Inline Installation guide, and when a website user clicks the installation button the app gets installed.
At the installation time (i.e. chrome.runtime.onInstalled.addListener(function() {}) in background.js), how can the app read a value (of DOM element or JavaScript variable - an ID of the logged in site visitor) from the HTML page hosting the installation button?
All online advise I found, is to use content scripts for extensions. The above-mentioned guide says: "Extensions can communicate with the embedding page via content scripts".
What is a solution for apps?
Sorry, but I don't believe that apps are able to get to the underlying page that they are installed from at all. The idea is that they should be sandboxed in their own private universe and not be able to affect anything outside their own window.
Extensions, on the other hand, are made to be able to access DOM of web pages.
So, I believe to do what you ask you will need to make an extension instead of an app.
If you just need to communicate some small piece of information from the web page to your app, look for another (out of band) method to do this.

Activate chrome app from web page?

I am building a packaged chrome app (It is needed as I want to access chrome.socket). I have a website from which I would like to call my app (if installed or ask the user to install it) by clicking a link. Is this possible ? Not able to find any easy way for this workflow.
The url_handlers might be the best way to achieve this.
You can also use the externally_connectable manifest property to declare that your website can connect to your app, then call chrome.runtime.sendMessage or chrome.runtime.connect from your webpage and handle it in an chrome.runtime.onMessage handler in the app.
Which one is better suited depends on your needs. The url_handlers is an easier way, but it will permanently assign the URL on your link to your app, so you won't be able to use it for anything else if the app is installed. The externally_connectable is a harder way, but it enables a much more elaborate bidirectional communication between your website and the app.
You can even use a combination of the two approaches, if you need: launch the app using the url_handlers feature, then establish a communication channel back to the website once the app is up and running.
Apps can now (as of Chrome 31 I believe) register to handle urls by adding url_handlers in their manifest and detecting the url causing the app to launch in the chrome.app.runtime.onLaunched event. If the app doesn't launch, your hosted web site will be loaded an can present an inline installation with chrome.webstore.install.

Chrome Extension Development - need help getting started

I'd like to try my hand at some Chrome Extension Development. The most I have done with extensions is writing some small Greasemonkey scripts in the past.
I would like to use localStorage to store some data and then reveal the data on a extension button click later on. (Its seems like this would be done with a popup page)
How do I run a script everytime a page from lets say http://www.facebook.com/* is loaded?
How do I get access to the page? I think based off my localStorage requirement I would have to go down the background_page route (correct?) Can the background page and popup page communicate across the localStorage?
UPDATE:
I'm actually looking to learn the "Chrome way". I'm not really looking to run an existing Greasemonkey script
Google actually has some pretty good documentation on creating extensions. I recommend thoroughly reading the following two articles if you haven't already done so:
http://code.google.com/chrome/extensions/getstarted.html
http://code.google.com/chrome/extensions/overview.html
If you want to give your extension access when the user browses to Facebook, you'll need to declare that in the extension's manifest.
Unless you're wanting to save data beyond the life of the browser process, you probably don't need to use local storage. In-memory data can just be stored as part of the background page.
Content scripts (which run when you load a page) and background pages (which exist for the duration of the browser process) can communicate via message passing, which is described here:
http://code.google.com/chrome/extensions/messaging.html
Overall, I'd suggest spending some time browsing the Developer's Guide and becoming familiar with the concepts and examples.
Chrome has a feature to automatically convert greasemonkey scripts to extensions!