My Service Worker does not load the page offline and no Manifest is fetched - json

I am creating a progressive website www.seta-capital.com, on the inspector I do not receive any error, I see the registration of the service worker but the website doesn't load offline, Lighthouse tool says that no service worker is present and no manifest is fetched. Can you please tell me if I am doing something wrong?
I created my very simple manifest.json
{
"short_name": "Seta",
"name": "Seta Capital",
"icons": [
{
"src": "../img/logo_no_writing.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "../img/logo_no_writing.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": "/",
"background_color": "#3367D6",
"display": "standalone",
"scope": "/",
"theme_color": "#3367D6"
}
In my index.php I added my Script to locate the json
And I added a service Worker registration script:
<script>
if('serviceWorker' in navigator) {
navigator.serviceWorker
.register('../js/sw.js')
.then(function() { console.log("Service Worker Registered");
});
}
</script>
Finally my sw.js file is:
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open('setacapital').then(function(cache) {
return cache.addAll([
'../',
'../index.php',
'../css/Formcss.css',
'../js/jquery-2.1.0.min.js',
'../js/circle-progress.min.js',
'../css/Formcss2.css',
'../img/bg.jpg',
]);
})
);
});
self.addEventListener('fetch', function(event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});

that won't work.
your index.php is probably a complex dynamically creating file.. depending on a lot of other php code and database queries.
you would need to cache a pre-rendered file like an index.html file.

Related

Migration issue Manifest-2 to Manifest-3 ( service worker inactive )

I am migrating my chrome extension from manifest version 2 to 3.
There is a problem in injecting the file with the click of the extension icon.
Manifest.json
{
"manifest_version": 3,
"name": "Name of Extension",
"description": "description",
"version": "1.0.0",
"background": {
"service_worker": "background.js"
},
"permissions": [
"activeTab",
"scripting"
]
}
Background.js - Manifest version 3 ( This code is not working )
chrome.action.onClicked.addListener(function() {
chrome.scripting.executeScript({
files: ['"function.js"']
});
});
background.js - Manifest version 2
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(tab.id, {file: "function.js"});
});
Use tab parameter as described in the documentation for onClicked
Specify tab's id as described in the documentation for executeScript
Remove the nested quotes in the file name
chrome.action.onClicked.addListener(tab => {
chrome.scripting.executeScript({
target: {tabId: tab.id},
files: ['function.js'],
});
});

Can't pass Chrome Lighthouse PWA test even when service work is registered

I'm building a progressive web app bundled by webpack which uses service workers generated by workbox. When I ran the Chrome Lighthouse on the web app, however, it complains that:
Current page does not respond with a 200 when offline
start_url does not respond with a 200 when offline
Does not register a service worker that controls page and start_url
More disturbing is that even though this web app works as a PWA on my Windows desktop, it doesn't work on Android Chrome as the "Add to Home Screen" option didn't pop up.
Link to web app: https://alienkevin.github.io/try-elm-rust-pwa/
Link to full repo: https://github.com/AlienKevin/try-elm-rust-pwa/tree/master
Here's the log message proving that the service worker is registered:
Here's my webpack.config.js:
const CopyWebpackPlugin = require("copy-webpack-plugin");
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const workboxPlugin = require('workbox-webpack-plugin');
const path = require('path');
module.exports = {
entry: "./bootstrap.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bootstrap.js",
},
mode: "development",
plugins: [
new CleanWebpackPlugin(),
new CopyWebpackPlugin(['index.html', '*.ico', '*.png', 'manifest.json']),
new workboxPlugin.GenerateSW({
swDest: 'sw.js',
clientsClaim: true,
skipWaiting: true,
}),
],
};
Here's my manifest.json:
{
"short_name": "try-elm-rust-2",
"name": "try-elm-rust-2",
"icons": [
{
"src": "./android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "./android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#f74c00",
"background_color": "#ffffff"
}
I'm aware of a similar issue #6342 on lighthouse but the sample they provided didn't help me.

Add to Home Screen not prompt after Beforeinstallprompt event fired

Add to home screen not prompt even after its meets all PWA specification and checked by on Light House.
I have tried below code to check whether app already installed or not. but appinstalled Event not getting triggered and beforeinstallprompt Event gets fired successfully.
// appinstalled
window.addEventListener('appinstalled', (evt) => {
app.logEvent('a2hs', 'installed');
});
// beforeinstallprompt
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
deferredPrompt = event;
});```
// manifest.json
`{
"name": "demo",
"short_name": "demo",
"icons": [{
"src": "/static/public/icon/icon-192x192.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/static/public/icon/icon-512x512.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "/",
"orientation": "portrait",
"display": "standalone",
"theme_color": "#085689",
"background_color": "#085689",
"gcm_sender_id": "103xx3xxx50x",
"gcm_user_visible_only": true
}
`
// service worker
`self.addEventListener('fetch', (event) => {
console.log('event', event);
});`
Remove this line from your code
event.preventDefault();
Starting with Chrome 76, preventDefault() stopped the automatic mini-infobar from appearing
More details here
https://developers.google.com/web/fundamentals/app-install-banners/
event.preventDefault();
This is causing you the problem. Remove it.
By removing the event.preventDefault() you have no longer control over the event !
I suggest a lean manner to control the event, and get the information about installation, try the code below :
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
deferredPrompt = event;
deferredPrompt.prompt();
deferredPrompt.userChoice.then(result => {
if(result.outcome === "accepted") {
// TODO whatever you want to do when the user accept to install the app
} else {
// TODO whatever you want to do when the user refuse to install the app
});
})

Vue PWA blank screen after closing the app

I have created a PWA Application and it works fine.
Problem is:
User installing the PWA on Desktop and it works fine but after closing and re-opening it show blank page.
Also on mobile it show blank page after adding the website to home page.
var deferredPrompt;
LINK
https://gogrocery.tk
The problem is with the manifest.json start_url.
{
"name": "front-end",
"short_name": "front-end",
"icons": [
{
"src": "./img/icons/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "./img/icons/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"background_color": "#000000",
"theme_color": "#4DBA87"
}
Once installed the browser users index.html as the starting URL and that doesn't render the app. You should either change start_url to / or have /index.html render the app.
Add a route for '/index.html' into your default router. Use the same view/component as for '/'
...
routes: [
{ path: '/', name: 'home', component: HomeView },
{ path: '/index.html', component: HomeView }, // Fix for PWA at /index.html
...
Note: Don't use redirect for '/index.html', it doesn't fix the problem on mobile browsers :(

unable to install and view custom node in node-red

I am trying to make a Google Drive Upload Node in Node-Red. The ones that exist don't really work for the application I have in mind. Its a PhotoBooth which get triggered and the photo is uploaded to Google Drive in a Public Folder
I have been following the sample Node creation steps, and seems like there is no error while I run node-red-start, and the steps to link my new node also work without errors. My code is committed here on github
https://github.com/CuriosityGym/node-red-google-drive-upload
There are three files in the repo
package.json
{
"name": "node-red-google-drive-upload",
"description": "Node Red Node for Uploading files to Google Drive Using Auth",
"version": "1.0.0",
"author": "Rupin Chheda<rupin#curiositygym.com>",
"contributors": [
{
"name": "Rupin Chheda",
"email": "rupin#curiositygym.com"
}
],
"main": "index.js",
"repository": {
"type": "git",
"url": "https://github.com/CuriosityGym/node-red-google-drive-upload"
},
"bugs": {
"url": "https://github.com/CuriosityGym/node-red-google-drive-upload/issues"
},
"dependencies": {
"fs": "*",
"readline": "*",
"googleapis": "*",
"google-auth-library": "*"
},
"license": "Apache-2.0",
"node-red" : {
"nodes": {
"sample": "google-drive-upload.js"
}
}
}
google-drive-upload.js
module.exports = function(RED) {
function LowerCaseNode(config) {
RED.nodes.createNode(this,config);
var node = this;
node.on('input', function(msg) {
msg.payload = msg.payload.toLowerCase();
node.send(msg);
});
}
RED.nodes.registerType("sample",LowerCaseNode);
}
google-drive-upload.html
<script type="text/javascript">
RED.nodes.registerType('sample',{
category: 'function',
color: '#a6bbcf',
defaults: {
name: {value:""}
},
inputs:1,
outputs:1,
label: function() {
return this.name||"node-red-google-drive-upload";
}
});
</script>
<script type="text/x-red" data-template-name="sample">
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
</script>
<script type="text/x-red" data-help-name="sample">
<p>A simple node that converts the message payloads into all lower-case characters</p>
</script>
I dont see the node visible under the nodes list on the left hand side in the node-red UI.
Please suggest what I can change to make this work.
Thanks