Why does my PWA works on my phone but not on others? - progressive-web-apps

Good day, I'm currently working on PWAs (Progressive Web Apps), and I wanted to make a try:
Here is my app script:
if( 'serviceWorker' in navigator ) {
navigator.serviceWorker.register( '/service-worker.js' )
.then( ( reg ) => logServe( 'service worker registred', reg ) )
.catch( ( err ) => logServe( 'service worker not registred', err ) );
}
Here is my manifest:
{
"name": "WebApp",
"short_name": "PWA",
"description": "Progressive Web App",
"start_url": "/",
"icons": [
{
"src": "icon/icon-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/icon-256.png",
"sizes": "256x256",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/icon-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/icon-96.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "any"
}
],
"theme_color": "#000000",
"background_color": "#FFFFFF",
"display": "standalone",
"orientation": "portrait"
}
And here is my service worker:
self.addEventListener( 'install', evt => {
logServe( 'service worker has been installed' );
} );
self.addEventListener( 'activate', evt => {
logServe( 'service worker has been activated' );
} );
self.addEventListener( 'fetch', evt => {
logServe( 'fetch event', evt );
} );
To test it, I tried:
On my computer (with edge/chrome) -> I can see the default install button in the address bar, and allow me to install it
On my samsung phone through ngrok and on chrome -> It shows the button* I've set up to install the app and allow me to install it
Here is the script for my custom installation button*:
let deferredPrompt;
const addBtn = document.getElementsByTagName( 'a' )[0];
addBtn.style.display = 'none';
window.addEventListener( 'beforeinstallprompt', ( e ) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
// Update UI to notify the user they can add to home screen
addBtn.style.display = 'block';
addBtn.addEventListener( 'click', ( e ) => {
// hide our user interface that shows our A2HS button
addBtn.style.display = 'none';
// Show the prompt
deferredPrompt.prompt();
// Wait for the user to respond to the prompt
deferredPrompt.userChoice.then( ( choiceResult ) => {
if( choiceResult.outcome === 'accepted' ) {
console.log( 'User accepted the A2HS prompt' );
} else {
console.log( 'User dismissed the A2HS prompt' );
}
deferredPrompt = null;
} );
} );
} );
But as soon as I try on another device, it fails, I see the "service worker registered", but that's it.
So I checked on a PWA framework/validator (PWA Builder), and this validator told me I got all that is required to publish my PWA.
Any idea from where it's coming from?
EDIT
After sorting out my Lighthouse issue, I performed few tests and tried correcting some pointS, but I still have 2 issues I cannot solve:
a HTTP redirecting issue, I tried with the HTML tag <link rel="canonical" href="my https domain url"/> or with the following HTACCESS:
#RewriteEngine on
#ReWriteCond %{SERVER_PORT} !^443$
#RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R,L]
but I still have this issue (if possible, I would like to avoid making server set up to solve this.
a maskable issue on Chrome (even if I added maskables icons)
Here is my new icons definition:
{
"src": "icon/any/x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/any/x384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/any/x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/any/x128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/any/x96.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/any/x72.png",
"sizes": "72x72",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/any/x48.png",
"sizes": "48x48",
"type": "image/png",
"purpose": "any"
},
{
"src": "icon/maskable/x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icon/maskable/x384.png",
"sizes": "384x384",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icon/maskable/x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icon/maskable/x128.png",
"sizes": "128x128",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icon/maskable/x96.png",
"sizes": "96x96",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icon/maskable/x72.png",
"sizes": "72x72",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "icon/maskable/x48.png",
"sizes": "48x48",
"type": "image/png",
"purpose": "maskable"
}
Here is what happen on Edge - Chrome when doing a Lighthouse test (Edge vs Chrome)
lighthouse edge and chrome

Related

Getting No Manifest Detected error while building PWA

I am trying to build a PWA, and in that process have added a manifest file to of my webpage, but I am getting "No Manifest Detected" in the Application tab in Chrome Dev Tools.
I have seen other threads on this and have tried solutions like restarting, clearing the cache etc. but to no avail.
I tried some other tools like https://manifest-validator.appspot.com/ and they don't seem to show any issues in the manifest file.
You can also try the website at https://beegle.app/apporter-book-help and see that when you do "view source", you can find manifest file added in header and the manifest file link working fine too.
Here's how it has been added
<link rel="manifest" href="/manifest.json">
Here's how the file looks like:
{
"name": "Beegle Apporter",
"short_name": "Apporter",
"icons": [{
"src": "/beegle-logo-128x128.png",
"sizes": "128x128",
"type": "image/png"
}, {
"src": "/beegle-logo-144x144.png",
"sizes": "144x144",
"type": "image/png"
}, {
"src": "/beegle-logo-152x152.png",
"sizes": "152x152",
"type": "image/png"
}, {
"src": "/beegle-logo-192x192.png",
"sizes": "192x192",
"type": "image/png"
}, {
"src": "/beegle-logo-256x256.png",
"sizes": "256x256",
"type": "image/png"
}, {
"src": "/beegle-logo-512x512.png",
"sizes": "512x512",
"type": "image/png"
}],
"start_url": "/apporter-book-help",
"display": "standalone",
"background_color": "#3E4EB8",
"theme_color": "#2F3BA2"
}
Any suggestions and thoughts on what could be going wrong?
Finally managed to solve it. I was using some plugin which was adding "body" tag within "head", and somehow that was causing the manifest to not get detected.

Flutter PWA not showing `Add to Home Screen` option

Flutter version: 1.19.0-4.0.pre
I am trying to generate a PWA app using Flutter web, but when I open the web app, it doesn't behave as a PWA should and it doesn't show add to home screen banner either on my android device.
Here's my manifest.json file:
{
"name": "Flutter PWA Demo",
"short_name": "PWA Demo",
"start_url": ".",
"scope": ".",
"display": "standalone",
"background_color": "#FFFFFF",
"theme_color": "#E50D7F",
"description": "A Flutter pwa application.",
"orientation": "portrait",
"icons": [
{
"src": "images/icons/icon-72x72.png",
"sizes": "72x72",
"type": "image/png"
},
{
"src": "images/icons/icon-96x96.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "images/icons/icon-128x128.png",
"sizes": "128x128",
"type": "image/png"
},
{
"src": "images/icons/icon-152x152.png",
"sizes": "152x152",
"type": "image/png"
},
{
"src": "images/icons/icon-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "images/icons/icon-384x384.png",
"sizes": "384x384",
"type": "image/png"
},
{
"src": "images/icons/icon-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
]
}
I tried it on master and dev but it doesn't work. It doesn't show add to home screen option on device or desktop chrome browser.
Firt become sure that you have registered "flutter_service_worker.js" in your "index.html" file, just like below:
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
navigator.serviceWorker.register("/flutter_service_worker.js");
});
}
Then open your pwa on chrome, right click on page and select "Inspect" option. Then go to "Application" tab and check if there is an error for "Manifest" and if there is you should fix it.
Then check "Service Workers" tab to see if "flutter_service_worker.js" is registered.
If it is registered and the "Manifest.json" file works fine, then you should see "Add to Home screen" option.

Change Blazor offline chrome window style

Can we change the style of the window that host Blazor offline apps, Like changing title bar color or set an icon or change default window back color.
yes - in the manifest.json - see https://pwa-workshop.js.org/1-manifest/#manifest-fields
example:
{
"name": "myapp",
"short_name": "myapp",
"start_url": "./",
"display": "standalone",
"background_color": "#B4ECF9",
"theme_color": "#F00BAA",
"icons": [
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
}
]
}

How can I use bootstrap with cloudflare apps

I have tried adding bootstrap css to the install.json file the following way, but I got an error:
,
{
"type": "style",
"src": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
}
How can I add it to the project and use it?
I tested this in my install.json and it worked fine
"resources": {
"body": [
{
"type": "style",
"src": "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
},
{
"type": "style",
"src": "./source/app.css"
},
{
"type": "script",
"src": "./source/app.js"
}
]
},
"preview": {
"handlers": [
{
"options": ["_default"],
"execute": "INSTALL_SCOPE.setOptions(INSTALL_OPTIONS)"
},
{
"options": ["_product"],
"execute": "INSTALL_SCOPE.setProduct(INSTALL_PRODUCT)"
}
]
},
"options": {}
}
There is likely something wrong with the JSON of your install.json. You could try copy and paste your install.json in this tool to test: https://www.cloudflare.com/apps/developer/install-json-tester

Broccoli asset rev fingerprint urls in json file

My rails app and index.html file are hosted on heroku and the rest of the assets are on s3, there's a manifest.json file that is required in order to enable mobile web app mode for chrome on android that looks like:
{
"short_name": "Kinlan's Amaze App",
"name": "Kinlan's Amazing Application ++",
"icons": [
{
"src": "launcher-icon-2x.png",
"sizes": "96x96",
"type": "image/png"
},
{
"src": "launcher-icon-3x.png",
"sizes": "144x144",
"type": "image/png"
},
{
"src": "launcher-icon-4x.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "/index.html",
"display": "standalone",
"orientation": "landscape"
}
In my brocfile.js I have included the json extension to the list of fingerprintable files.
The actual file gets fingerprinted but the contents such as "src": "launcher-icon-3x.png" do not.
Anyway to do this or do I need to make an in-Repo addon to handle the creation of the file?
After looking through the source the following can be done by adding json to the replaceExtensions option:
var app = new EmberApp({
fingerprint: {
prepend: fingerprint,
extensions: ['js', 'css', 'png', 'jpg', 'gif', 'svg', 'json'],
replaceExtensions: ['html', 'css', 'js', 'json']
}
});