Chrome web browser allow persistent storage - jquery-mobile

Running Ripple emulator (phonegap) on Ubuntu Linux. In my app (jquery mobile) I want to create a file (using persistent storage), problem is that the allowed storage quota is 0 for persistent storage and 2gb for temporary storage.
So this works :
window.webkitStorageInfo.requestQuota(LocalFileSystem.TEMPORARY, 1024*1024, function(grantedBytes) {...});
but if i change to LocalFileSystem.TEMPORARY then grantedBytes == 0.
Any ideas ?

I just faced the same problem.
Persistent storage requires user's permission in Chrome.
You can request it by:
window.webkitStorageInfo.requestQuota(window.PERSISTENT, 5*1024*1024 /* 5MB */, function(grantedBytes) {
window.webkitRequestFileSystem(window.PERSISTENT, grantedBytes, onInitFs, errorHandler);
}, function(e) {
console.log('Error', e);
});
I found that solution at blackberry support forum and at least for me it worked.

Related

net:ERR_CONNECTION_RESET from a specific website in electron app

I Have an Electron app with a Webview. When i set the webview src to the website https://www.zap.co.il
i'm receiving the error: net:ERR_CONNECTION_RESET. The weird things are:
It's happening only for that website, i'm not receiving this error from any other website.
I'm able to reach the website from any other browser on my computer (Chrome, Chromium).
This is happening in both Windows and Mac platforms.
A colleague of mine have the same App installed on her computer, and she is experiencing the same behaviour from a different computer (and network)
There is no antivirus Installed that may intercept and no proxy configured. I have tried to reset the network, clear cache and cookies, change the MTU and basically any solution i found on the internet, and since it's happening for my colleague too, i suppose it has nothing to do with a network issues.
And since i can reach the website from other browsers, I think the issue is probably relates to Electron.
I'm Using the versions:
electron: 8.2.1
electron-builder: 22.4.1
The problem was that electron add's few properties to the user agent string. and this specific website is not accepting custom properties in the user agent (probably for security reasons). I fixed it by removing the additional properties from the webview's user agent:
webview.addEventListener('dom-ready', () => {
const uaArr = webview.getUserAgent().split(" ");
const newUaArr = uaArr.filter((uar => !uar.startsWith('Electron')));
webview.setUserAgent(newUaArr.join(" "));
});

Navigator.mediaDevices.getUserMedia not working on iOS 12 Safari

As of iOS 12, navigator.mediaDevices.getUserMedia() is returning an error in Safari.
To recreate this, open iPhone Web Inspector, then run this snippet in the console:
var constraints = { audio: true, video: { width: 1280, height: 720 } };
navigator.mediaDevices.getUserMedia(constraints)
.then(function() {
console.log('getUserMedia completed successfully.');
})
.catch(function(error) {
console.log(error.name + ": " + error.message);
});
You'll see that this runs successfully in desktop browsers, and in iOS 11 Safari, but fails in iOS 12 Safari.
NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
Any idea why?
note: This is happening prior to the user being asked if their camera can be accessed, ruling out the possibility of it being because the user denied permission.
Setting these three attributes before calling getUserMedia solved the problem for me:
video.setAttribute('autoplay', '');
video.setAttribute('muted', '');
video.setAttribute('playsinline', '');
For some reason video.setAttribute() works but trying to assign the value directly to the video object for example video.muted = '' does not.
Also it appears that it's not necessary to call video.play().
Simply setting the video.srcObject to the stream returned by getUserMedia worked for me.
This medium post has a link to a working demo & source code.
There are two possible reasons for immediate NotAllowedError at the moment:
1. getUserMedia requries https
Safari seems to require https for camera and mic access, both in iOS and OSX.
With an https link, iOS Safari 12 works for me; same link in http gets NotAllowedError.
Chrome has the same requirement. This is consistent with the direction of the specification, which recently has restricted getUserMedia to secure contexts. Browsers who have yet to update, still expose navigator.mediaDevices in http, but getUserMedia always rejects with NotAllowedError.
In the future, expect browsers to remove mediaDevices entirely in http, to comply with the spec.
2. getUserMedia requires feature policy in cross-origin iframes.
This appears new with Safari 12. In iframes, getUserMedia's feature policy is off by default for cross-origin content.
This works for me:
<iframe
allow="camera;microphone"
src="https://webrtc.github.io/samples/src/content/getusermedia/gum/">
</iframe>
This doesn't work:
<iframe src="https://webrtc.github.io/samples/src/content/getusermedia/gum/">
</iframe>
...and in addition to failing with NotAllowedError, Safari warns in web console:
The top-level frame has prevented a document with a different security origin to
call getUserMedia.
This is also a recent update to the spec.
Turns out my particular issue was a bug in 12.01. Every device with that version had the issue, and as soon as I updated them to a newer version it went away.

Cannot play offline video in production electron app

I have an electron/ember app that allows users to store a video offline and play it later. The ember app uses a video tag with a computed property to swap out the video src from the server with the offline link. I am storing it using electron.getPath("userData") so for macOS it's in ~/Library/Application Support/<appname>. The problem comes when I create the signed distributable. The offline support works just fine when running with ember electron but as soon as a I sign and package it for release it no longer works. The video player itself loads but is just blank. Is there some limitation with using local files in release mode for electron?
The answer is https://github.com/electron/electron-compile/pull/199
tldr; skip authenticity checks on local files
const { app } = require("electron");
const { addBypassChecker } = require('electron-compile');
addBypassChecker((filePath) => {
return filePath.indexOf(app.getAppPath()) === -1;
});

How to make deferred deep linking?

How to make deferred deep linking and generate unique mobile signature. I try using IP Address, screen-size, OS version, device name but still not get succeed.
The comment links to a great answer, certainly. High level, here are the steps:
Your links should point to a page on your site that collects a digital fingerprint
That page should collect, at minimum, IP address, OS, OS version and screen size (width and height). Should send to your server and place in a persistent store. Redis works great for this because of its fast lookup times. Also record some sort of unique identifier for which link was clicked (that could be the value in redis).
Then redirect to the app (URI scheme) and have a fallback to the App Store/Play Store. Here's an example for iOS. The beauty of the iframe is that it kills the alertView if the app is not installed. This should be placed in the body:
<script type="text/javascript">
window.onload = function() {
// Deep link to your app goes here
document.getElementById("l").src = "my_app://";
setTimeout(function() {
// Link to the App Store should go here -- only fires if deep link fails
window.location = "https://itunes.apple.com/us/app/my.app/id123456789?ls=1&mt=8";
}, 500);
};
</script>
<iframe id="l" width="1" height="1" style="visibility:hidden"></iframe>
When a user opens your app, send up the same combination of params to your servers and search your persistent store to see if this device recently clicked on a link. Send a response down to your app (e.g. { link_id: "1234" } or { link_id: -1 }) Your app logic should then respond based on which link was clicked.
Hopefully this makes sense. We do this at Branch and can assure you that it's harder than it looks to roll this solution from scratch. There are a ton of edge cases introduced by individual browsers and even individual apps (e.g. when links are shared to Twitter and clicked on in the native Android app). But at it's core fingerprinting is relatively simple. Hopefully the above was helpful.

Can a remote webpage loaded in Phonegap hybrid iOS app save data to iOS filesystem?

We have a mobile web app hosted on a server. We want to convert it into a hybrid app using Phonegap, but we do not want to embed the html and other code in the www folder in the hybrid app. We want the pages to remain remote so that updating them can be independent of the app. This is an internal iOS app and we are not planning on submitting it to Apple.
This mobile web app makes some webservice calls which return back some json response. In the hybrid app, we want to save the json response on the iOS device filesystem. I know if we would embed the web app in the www folder of hybrid app, we can easily do so using plugins. But since the web app is remotely hosted, will it still be possible for phonegap plugins to talk to the javascript code and get the webservice response and save to the device?
Yes you can use the File plugin to write, read, delete, upload and download files.
http://docs.phonegap.com/en/3.3.0/cordova_file_file.md.html#File
Example code for communicating with the plugin from your HTML in JS:
document.addEventListener("deviceready", onDeviceReady, false);
// device APIs are available
//
function onDeviceReady() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function gotFS(fileSystem) {
fileSystem.root.getFile("readme.txt", {create: true, exclusive: false}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.createWriter(gotFileWriter, fail);
}
function gotFileWriter(writer) {
writer.write("some sample text");
}
For communicating with a web service from your app, you will have to update your config.xml with <access origin="*" />. jQuery Ajax works well for retrieving JSONs.

Resources