Firefox OS - Launch external link inside Firefox OS app and retrieve its content - firefox-os

I have a Firefox OS app in which I have opened an web page via mozbrowser attribute.
<iframe id="inlineFrameExample"
mozbrowser=true
src="<some external link>"
</iframe>
How can we retrieve DOM content of the iframe?

You can retrieve DOM content via executeScript() method present in Browser API. It will run the script against the iframe and will allow you to do DOM computation tasks.
Note: The example mentioned in the document didn't worked but the syntax given below worked for me. The diff is is passed as string.
iframe.executeScript('put_your_script_here', {origin: 'domain_name'});

Related

Xamarin HybridWebView always opens in Browser with xamarin.iOS when using Appcues script

When i check in the script from Appcues then i see it trieds to embed an iframe to my body element.
I can see that adding an iframe with <iframe src="https://www.google.com"></iframe> in my website. That iOS apps opens to the native browser to google immediately. The same result when adding an Appcues script.
I can ignore the navigate to google url but if i do that for Appcues. Appcues doesn't get shown in my app. This works fine on Xamarin.Android

How to execute a callback on the devtools page from page's JS?

I am trying to write a Chrome devtools extension for a JS SDK we have developed. This SDK has an API addEventListener (the events are not DOM events) that I would like to use to be able to display all the events that are being published in the devtools panel I made.
Basically I would like to be able to have the following code in my devtools page script :
chrome.devtools.inspectedWindow.eval(
"mySDKonTheContentPage", function(result, isException){
mySDK =result;
mySDK.addEventListener("myEvent", function(){
doSomethingInDevtoolsUI();
});
});
Since content scripts don't have access (do they?) to the page's JS objects, I don't really know where to start.
In the script on your page, you can use window.postMessage to send your data to the content script. From there you can set up communication between the content script and the DevTools panel via a background page.
See: Messaging from Injected Scripts to the DevTools Page and Messaging from Content Scripts to the DevTools Page for examples of this in the documentation.

After deletion of chrome extension remove some html elements from website

Hi I am new to chrome extension. I have build the basic chrome extension and I want to install it using inline installation. I followed the following link :
https://developer.chrome.com/webstore/inline_installation#already-installed
All is working properly. I want to check if extension is already installed or not so I referred the above document, whenever user install the extension at that time we are appending the new div using content script to my installation page on website. If that div is present it means the extension is already installed.
Following code is added in my content_script of chrome extension for appending the div whenever the extension is installed:
var isInstalledNode = document.createElement('div');
isInstalledNode.id = 'extension-is-installed';
document.body.appendChild(isInstalledNode);
Then my installation page can check for the presence of that DOM node, which signals that the extension is already installed:
if (document.getElementById('extension-is-installed')) {
document.getElementById('install-button').style.display = 'none';
}
But I am facing one problem, whenever I deleted my extension from settings/extensions, still the div is present on extension's installation page.
Is their any provision to remove the div when my extension is deleted or removed from browser?
You can't catch the uninstallation event for your own extension, though there is an management.onUninstalled, it is used for listening to other extensions/apps. See following answer for more details:
How to listen to uninstallation event in javascript from a chrome extension?
I just come up with two workarounds, one is creating another extension to listen to the uninstall of your first extension; another one is using runtime.setUninstallURL to visit a URL upon uninstallation, you can do something in server if you want.
BTW, for isInstalledNode, you needn't/shouldn't set the id, since there may be other elements in the webpage with the same id, you just need to create the node and use document.body.contains(isIntalledNode) to check if it exists.

mailto links not working in Chrome and Safari Mobile

In my jQuery Mobile App, I have a mailto link, its href attribute is dynamically generated and it is 'clicked' via jQuery.Here is the link code:
<a id="mealLink" href="mailto:123#123.com" style="display: none;">This is the mailto
link</a>
A click handler is attached to it like this:
$('#mailLink').bind('click', function() {
window.location.href = $(this).attr('href');
});
Lastly,a function creates the href attribute for the link with emailaddress, subject and message body and click is simulated via jQuery:
$emailAddress= ..
$subject= ....
$body=...
$emailString="mailto:"+$emailAddress+$subject+$body;
$emailLink= $("#mealMail");
$emailLink.attr("href",$emailString);
$emailLink.click();
Now, this code is working perfectly in:
Mozilla desktop
Safari desktop
Android
But not working in:
Safari Mobile
Chrome desktop
Any suggestions?
After searching for complex solutions, I found a much easier solution by chance. The issue here is that if a mailto link is directly clicked, it works in all browsers, but if it is indirectly clicked, such as via jQuery .click() function, it does not work in all browsers. Therefore, here is my implementation:
This is a mail to link
$emailAddress= ..
$subject= ....
$body=...
$emailString="mailto:"+$emailAddress+$subject+$body;
$emailLink= $("#emailLink");
$emailLink.attr("href",$emailString);
Now, depending upon the context of an application, the href parameter of the link can be setup and when this link is clicked, it works. I have tested in following browers:
Mozilla Firefox Desktop
Safari Desktop
Chrome Desktop
Safari mobile on ipad 1
You should not use mailto:
Check if is not better to create a simple "Contact us" form.
But still, take a look at this: i-cant-get-mailto-links-to-open-the-mail-app-from-mobile-safari-when-using-jqto

Google Chrome Extension Adding iframe from source

I'm trying to load myframe.html inside an iframe and attach that iframe to the DOM of the current page. Is this possible, if myframe.html is part of my extension source?
I was thinking something like
var iframe = document.createElement("iframe");
iframe.setAttribute("src", "myframe.html"); //what would be my path here, if this were possible?
document.body.appendChild(iframe);
It should be possible, use a content script to inject javascript into the page and then use the chrome.extension.getURL() method to get the correct URL to your file hosted inside your extension

Resources