javascript to open a firefox extension - javascript

I try to open a new tab of Firefox extension (URL starts like chrome://xxx/content) in a web page.
I have tried window.open().location='chrome://xxx/content';, but I always got a new tab like http://chrome://xxx/content.
So the question is whether there is a solution to open the Firefox extension in web-page JavaScript.
If the answer is yes, how to realize it?

The answer is "no". A web page is not allowed to open browser/extension user interface elements, for security reasons.
Now the web page could notify the extension that a particular extension page needs opening: https://developer.mozilla.org/en/Code_snippets/Interaction_between_privileged_and_non-privileged_pages. But given that your question doesn't provide any details on what you are trying to achieve it isn't clear whether this is a viable approach for you.

Related

How can I open URLs in a new tab across all browsers with a bookmarklet?

I writing bookmarklet to open all twitter img in newtab but it not give same result with difference browser
This is result I try
firefox 64.0.2 work on normal and private but it change original url to my bookmarklet script
firefox 64.0.2 portable not working both
chrome 71.0.3578.98 only 1 image on normal ,incognito not working
vivaldi 2.2.1388.37 work on normal perfectly ,private not working
Ex. twitter link
https://twitter.com/RadioPakistan/status/1084765300183179264
EDIT: I make it to use but...
firefox sitll open newtab and replace original tab url to bookmarklet script url
Edit2: I just add history.go(-1) after loop for prevent firefox redirect web url to script url
javascript:$=jQuery;$(".twOpenOriginalImage_touched").each(function(){var url=$(this).attr("src");window.open(url,"_blank");});
working bookmarklet
javascript:$=jQuery;$("img[data-aria-label-part]").each(function(){var url=$(this).attr("src");window.open(url,"_blank");});
C&P
I have done some searching but have found very little documentation on what can be done in a bookmarklet which cannot be done in a normal web page
That is because there is essentially none. For all practical purposes, running a bookmarklet is exactly the same as running script on the page. It is almost precisely equivalent to clicking a link on the page that has href="javascript:.."
although having written some bookmarklets already it seems they have a bit more privileged status than a normal web page (although this seems to vary by browser).
I've have also written and researched a lot about bookmarklets (check my SO history). I have found only 2 significant differences.
1.) You can use %s in the bookmark's URL in combination with a bookmark keyword for argument substitution via the URL bar.
2.) There is a weird hack in Chrome (which could easily get closed with some future update) which lets a bookmarklet open a URL in a new tab and then run code in that tab if and only if the user does CTRL+click on the bookmarklet. But that still doesn't let you do anything to tabs which are already open.
If you know others, let me know.
The only solution is to create a browser extension. If you can write a bookmarklet, it isn't much more complicated to write a very basic extension.

Can a Chrome extension act as a web app in place of a website?

I'm trying to develop a Chrome extension that is supposed to completely replace a specific website's pages with a new UI. In other words, when the user visits said website, the extension should "intercept" it seamlessly and display the new "app" (preserving the URL and without opening a new tab or window). I currently use a content script to manipulate the DOM, but it's too messy.
Chrome apps such as Google Docs achieve the same goal through URL handlers, but they're not an option since they're now deprecated.
Currently, I'm aware of two options:
Intercept the URL and redirect it to an extension URL. I want the URL to be preserved.
Use a content script to stop the page from loading at document_start (using window.stop()) and then "inject" the new app. Apparently, that works, but it sounds quite hacky and prone to unexpected glitches.
What I'd like to know:
Is the second approach good enough? What limitations and other issues will I face if I use it?
Is there any other approach that is at least as good (and preferably designed for this purpose)?
You can't open a chrome app in a tab, only in a window. I don't think they have content scripts either.
Also, chrome apps are now only available on chrome os when you publish it for the first time (existing chrome apps work for any os).
To solve your question, you could use an extension with content scripts and just open up an iframe fullscreen so the url is preserved in the omnibox and it could have the page you want in the iframe as the page that would be in the app.
Content handlers are meant for opening a special protocol url to do something like send an email, etc. Examples would be like tel://, sms://, mailto:, etc.
So you would not want this. Also they aren't that noticable when approving to handle the protocol.

Can a chrome extension be opened when requesting specific external protocol?

I want to write a chrome extension that is triggered when the browser redirect to a specific external protocol: myApp://...
I googled a bit and didn't find an easy meta-data way to do so.
is there a way to define it in the manifest?
I want the extension to open a popup then, and I'll wait for it in my automation testing.
You can, in theory, use a protocol handler with navigator.registerProtocolHandler, but there are limitations:
Custom protocols must start with web+ in Chrome, e.g. web+myApp:
There is no way to declare this in a manifest; according to this feature request to add that possibility, currently it will pop up an allow/deny infobar for the user.
In any case, opening a popup programmatically is impossible. At most you can open an extension page in a tab.

How can I gently "bust" UIWebview?

Recently, a few developers have started creating apps which do nothing more than point at state-owned content (free, public property) through UIWebViews. This wouldn't ordinarily be a problem, except the apps are all ad-supported and some are even paid. Essentially, they're making money on state-owned content.
My question is this: how can I force the site to open a new Safari window rather than display in the UIWebview (which is wrapped in their app's branding)? I am able to detect UIWebview using the following, but am unable to do anything besides simply hide the content. I'd prefer it to provide a link to our content which then opens in Safari.
This is how I'm detecting UIWebview:
var is_uiwebview = /(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent);
unfortunately its fairly trivial for a developer to force the User-Agent string to anything they want, so your attempts to thwart these developers might only be temporary. You can't force your content to be viewed in a browser. A user could use a tool like CURL to view your content also...
Once you detect that you're in the UIWebview, you need to fire a window.open() to put your content in a fresh window.
This talks about some quirks that make it a little tricky (but not impossible): Opening popup links in UIWebview. Note that the question there is the reverse of yours, but the accepted answer does show how to get UIWebview to pop a new window via Javascript.
This has been a concern ever since the Web began. You can't stop people from scraping your content, but you can make it hard to reframe it.
Edited to add
Unfortunately for you, the app can intercept window.open(): UIWebView respond to Javascript calls
I suppose you could always give up and show a banner that says something like "you paid for this data with your taxes, you shouldn't pay for it again with ads. Just open a browser and go to ... "
You can find out if it is a WebView or Mobile Safari, as seen in this thread. The problem is, that you could only open Safari via a custom URL scheme, but think, only http://, https:// etc. work. Even if there would be something like safari-http://, the programmers of the apps with the UIWebView could catch that request and redirect it back into the web view. So, I'm sorry to say: That's not possible.

Can I open a local file, in Firefox, with a link link like: file:///home/user [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Firefox Links to local or network pages do not work
Hi all,
I would like to know how can i offer users that connected in my web site (in JAVA - JSP pages) to show the contents of files in THEIR PC over Web browser.
More precisely, i want to have a button, on what when user click, it open a new TAB or new window (of the browser) with path like : file:///home/user...
I did try with my flowing snippet of codes:
<script type="text/javascript">
[...]
window.open("file:///home/user...");
[...]
</script>
this works fine when i open my html file manually with Firefox, but when i try to load it in a application server (Java EE), it doesn't work at all. I get this kind of message in my error console (of firefox):
Security Error: Content at http://localhost:8080/MyProject/test.jsp may not load
or link to file:///home/user.
It seems to be a problem related to the security policies of Firefox, still i didn't found any issues to resolve my problem ...
Do you have any ideas about this?
It's impossible because of security reasons.
Remote pages are not allowed to link to file:// pages because it allows attacks on the browser, and in some cases on the OS. For example, <img src="file:///dev/tty"> on Linux will hang the browser for most users (the few running it from a terminal will be able to recover by foregrounding it, but that's it).
It's not possible to read a local file through your web application, however, you can ask the user to upload the file first and then open it.

Categories