How can I launch a Chrome Packaged App through javascript? - javascript

I want to be able to launch my packaged chrome app via javascript either on-page or through an extension. Am I able to do this? I have done a fair amount of research with no answer in either direction. Can somebody at least point me in the right direction?

chrome.management.launchApp can be used to launch an app in an extension.
The API reference is available here: https://developer.chrome.com/extensions/management.html#method-launchApp.

You can make certain resources in your extension available, and then you should be able to "window.location" to that.
The URL scheme is chrome-extension://[PACKAGE ID]/[PATH].
Example:
//This is **not** in your packaged app, but in another web page
window.location = "chrome-extension://abdecbedphjijkaed/index.html";
In your packaged app, you'll need to declare which resources can be reached via a url in your manifest:
"web_accessible_resources": [
"images/my-awesome-image1.png",
"images/my-amazing-icon1.png",
"index.html"
]
See more: https://developer.chrome.com/extensions/manifest.html#web_accessible_resources
NOTE: This might not work. While the user can use "chrome://" urls, I'm not sure if web pages can

This feature is coming. See Issue 111422: Add ability for apps to register for URL handling.

Related

Could a google chrome extension be dormant yet invokable?

I am planning to develop a google chrome extension which will help with a home brew functional testing framework. Here's the puzzle:
There is no predefined url pattern where test pages could reside.
I don't want the extension to get invoked by a match-all url pattern and then decide the page is of no interest.
What I want instead is for the extension to be completely dormant and to be able to invoke it from within the test pages.
Is this possible? If so,
What should I have in my manifest?
How do I implement the wake-up call in my test page javascript?
Could the call be made whilst I am developing the extension, before it gets an id?
Edit:
This answer shows how a page could call an extension, but it needs an extension ID. Is there a way to get a temporary extension ID before the extension is published?
This is the first option I was thinking of but you do have to specify a second-level domain in the URL pattern.
Add this to your manifest.json
"externally_connectable": {
"matches": ["://.example.com/*"]
}
As such: *://*.example.com/*
not *://*.com
More information about chrome extension message passing here:
https://developer.chrome.com/extensions/messaging#external-webpage
You will need to specify an id for the communication. You can get your extensions id by visiting chrome://extensions
Not knowing your stack or build process I would set up a separate dev and prod config file with my dev and prod id's in the respective files. This will help avoid pointing to your development extension when you release your app to production.
An alternate option would be to inject on each page and invoke your script depending on the pages content.

redirect to ios application using php

i have read a lot of stack-over-flow Q&A and blogs about deep linking, the way i found convenient was to use header() function in my php code and use url within it to redirect. But when i put myApp:// in header function like this
header('Location: myApp://');
as redirect link it says
cannot open the page because too many redirects occur
then did some research and found this link
then according to the link, i used javascript method as
echo '<script type="text/javascript" charset="utf-8">window.location="360VUZ://";</script>';
to achieve the same
still this doesn't work as it changed the whole url i needed to open the app
it says
The requested URL /subFolder/myApp:// was not found
now i am not getting how the path is appending itself, all i need is to hit this
myApp://
url to open my application
any type of help or suggestion is appreciated ! thanks in advance!!
EDIT:
specifically when i am using JS to open app, it says
The requested URL /subFolder/myApp:// was not found on this server.
so all i need to do is somehow delete/remove the prefix path as it is finding the app on the server not on device and hit only 'myApp://', but still dont know how!? please help me!
With iOS 9.2, Apple deprecated the ability to launch apps via URI schemes in favor of Universal Linking. Consequently, this approach that you are exploring no longer works.
Your options are to set up Universal Linking on your own or to leverage a third party service like branch.io.

Script injection from outside the browser

I need to know how some softwares or programs inject html,css,js into webbrowser without installing any extension. once I open chrome or firefox I find ads on google homepage, facebook, youtube ... I need to know how they inject this, how to prevent it and how to know which program did it.
Here is my google home page on chrome
and all the extensions are disabled I even deleted most of them
What worries me the most, is that in google chrome devtool (ressources) the url of the displayed image is the same url of the google logo. when I enter this url I found the real logo of google
You have a computer virus somewhere affecting you.
Edit:
Multiple things could be happening:
Something is intercepting the network request and injecting a different image.
Something has replace your version of chrome with their own version. The base code is public and their version can do whatever they want.
keep in mind, that content de-facing might happen on the Router/Proxy level, too.
some routers have content filters and domain blacklists for child protection.
maybe it's some kind of joke on the router level, where someone added
a content replace filter.
check your computer (spybot + kaspersky)
check your router
check firewall and all networking filters in the chain

How to Launch a PDF from a Chrome Packaged App?

My chrome packaged app contains a PDF, and I would like to let the user view it. If I open it in the current frame I get the error "Chrome PDF Viewer is not Allowed".
Frankly, the chrome PDF viewer is pretty awful, so I'd rather let the user view it in their PDF viewer of choice anyway. If I disable the chrome PDF plugin (just as an experiment) and I try to open the PDF using chrome.app.window.open, it "downloads" the PDF, and then the user could open it. But this has two issues:
I can't realistically make the user go to chrome://plugins and do that disable
There isn't any browser window, so the user has no idea the download happened
Any suggestions? Opening PDFs that are embedded in my app is kind of a must-have feature for this app.
I've looked at this extensively, and have come to the conclusion that there's no way to get a Chrome App to open a PDF that's local. I, too, have tried data URIs.
I don't think the issue is the PDF support in the window, as it's still Chrome, or the size of the PDFs. Rather, I think it's just an engineering problem, one that might get solved someday.
As for me, I build the PDF in my Chrome App. Since I can't display it, and there's no server to upload it to, I write it to a file of the user's choosing and let the user deal with it on his/her own.
I've got this working, but whether it is a solution for you depends a lot on your use case. The solution has three parts:
Use pdfjs to do the actual rendering.
To get this running in a packaged app, you'd need to do some violence to the internationalization support. And even after you do that, you'll find that some PDFs refuse to load for no apparent reason whatsoever. So don't bother trying to make pdfjs work in a packaged app. Just:
Put your entire app into a <webview> with a persist partition, and use a HTML5 cache manifest to get all your files available for offline viewing.
Yeah, yeah, I know that cache manifests are not cool anymore. But if you can list all your files for use in a packaged app, then you are doing the one case where cache manifests actually work great.
Then use a packaged app to distribute a tiny wrapper around your page with the webview in it.
You'll also get the benefit that you don't have to rewrite your app to live within the draconian packaged app rules (eval, sync xhr, 2GB limit, etc.).
You can see a working example at m.kaon.com/c/ka (visit with Chrome to get the desktop app; if you visit that with Firefox, you'll get access to a hosted app that is using the same tricks). PDFs are down in the bottom "Why Choose Kaon" section.

Download multiple images without asking in Chrome extension

I am currently creating a Chrome extension (which uses javascripts mainly) that allows users to scrape the images on a webpage and download them. I have finished the link scraping part, and the code will return an array like:
["http://example.com/image1.jpg","http://example.com/image2.jpg"]
But how do I download all of the links in ONE CLICK? I tried listing all photos on a new tab and let the users to Ctrl+S save the page. But this greatly affects the UI and I do not like it. I do not host webpage so server side script may not be working.. Any other solutions?
As far as I know, Chrome extensions technically can't save files to disk like Firefox.
The only way to do this is using NPAPI
Unfortunately, extensions using npapi will most likely not be accepted by the Web Store due to security problems. Of course it'll be okay if you use it for yourself or host the extension on your website.
You can install and examize the code of the following extensions, maybe you can even use the provided npapi too:
Screen Capture (by Google) https://chrome.google.com/webstore/detail/cpngackimfmofbokmjmljamhdncknpmg
Chrome Toolbox (by Google) https://chrome.google.com/webstore/detail/fjccknnhdnkbanjilpjddjhmkghmachn
Awesome Screenshot: Capture & Annotate https://chrome.google.com/webstore/detail/alelhddbbhepgpmgidjdcjakblofbmce
Download Asisstant (by Google) - got killed I guess.

Categories