How does vue PWA use the precache? I still get "Page does not work offline" - vue.js

I have a vue application that I updated to have PWA capability. It uses the firebase messaging service that has overridden the service worker with its own firebase-messaging-sw.js file.
The service worker is registered, active and working, I have added the pwa in the vue.config.js file so that it generates the manifest.json. When you build the production version of the app the following code gets added to the top of the service worker.
importScripts("precache-manifest.7b51ac9589a6dc8041a85d8f1792defa.js", "https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js");
From what I see the percache works fine.
Should this be enough to get the site to work in offline mode?
Do I need to add some cache management myself?
What am I missing because I still get the "Page does not work offline" error message in Chrome's dev tools under the App manifest tab.

Looks like Google also picked up on the quick hack and the warning has returned.
So since of Chrome93 (AUG-2021) the quick hack, will not work anymore :
self.addEventListener('fetch', function(event) {})
Solution working "for now" (since we never know what requirements Google will add later on)
I've found a nice article which provides with a few solutions, the first one the author provides is Network-Falling-Back-To-Cache strategy:
your service worker will first try to retrieve the resource from your server. Then when it can’t do that — because for example, you’re offline — retrieve it from the cache (if it exists there).
self.addEventListener('fetch', function(event) {
event.respondWith(async function() {
try{
var res = await fetch(event.request);
var cache = await caches.open('cache');
cache.put(event.request.url, res.clone());
return res;
}
catch(error){
return caches.match(event.request);
}
}());
});
You can find all the information and alternative solutions in the article:
https://javascript.plainenglish.io/your-pwa-is-going-to-break-in-august-2021-34982f329f40
I hope this will help futur visitors.
Additional side note:
using the above code you might encounter the following error:
service-worker.js:40 Uncaught (in promise) TypeError: Failed to execute 'put' on 'Cache': Request scheme 'chrome-extension' is unsupported
This error is caused by chrome extentions like Augury or Vue dev-tools. Switching both off will cause the error to disappear.

You need to add this line in the serviceworker. It fools the browser into thinking that the page will work offline:
self.addEventListener('fetch', function(event) {}) // add this to fool it into thinking its offline ready

Related

Setting up a devserver.proxy in Vue3 with Axios requests

Im currently looking into setting up a proxy within my application for working within Sharepoint to update the cookies manually for local testing. have been using this https://medium.com/#joy.blanks/frontend-frameworks-inside-microsoft-sharepoint-e7694aa43c5d for reference and trying to convert the informaiton into a Vue3 project.
At present im struggling to get any conversation made and not entirely sure where it is falling over, i have tried to enable the debug settings to see if that reveals anything, but not getting any logs out in browser or console
I have the following added to my module.exports (have emited some data):
devServer: {
proxy: {
'https://<sharepoint_target>/_api': {
target: target,
logLevel: 'debug', // this what you want
changeOrigin: true,
}
}
}
and the Azios request is:
await axios.get(`${config.cmsEndPoint}/_api/lists/getbytitle('${list}')/items`,{ params});
but not able to even see if the proxy is kicking in as from the console give me any updated information around if the proxy server is working. Im not sure if its because im using a full url or if this would make a difference. The <sharepoint_)target> and the cms endpoing are the same string
From here i can then look at add a new header into the request as part of the proxy bypass section for the authication when testing locally.

The Cypress test does not open the Powerapps page

I'm trying to run simple cypress test and get error like this:
but if i change visit url to another - it opens normally:
I cant understand why this does this error come with this url:
"baseUrl":"https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a"
another visible error:
code:
describe("Create request", () => {
it("Should have a link that navigates to office365 login", () => {
cy.visit("/");
cy.get('div[class="loginNeededText_uf5ohz"]').contains('Sign in to start using Power Apps');
});
});
P.S. Also can't load https://apps.powerapps.com/ page. Error:
In general
With Cypress, you should not try to visit or interact with sites or servers you do not control. The main purpose of Cypress is testing, so when you try to do anything else with it, the task will become significantly more complicated (you can read more about it in the Cypress documentation).
If you really need information from a 3rd party site, it is recommended you do it through an API — mainly with the cy.request() method (e.g., Microsoft has quite an extensive documentation on how to work with the Office 365 Management API).
Your case
When you visit the apps.powerapps.com, you are being redirected to the Microsoft login page — it has a different domain name, which breaks a same-origin policy causing the cross-origin error in the Cypress console.
Seems that the page you specified in the baseUrl returns a 404 status code, along with some ugly CORS errors in the console, which suggest an issue with the app itself. After you solved those, you would most probably face the need of authentication anyway, and it is better to do it through an API.
When I use your base URL https://apps.powerapps.com/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a I see only blank screen and 404 error in the console, I am not redirected to login.
Maybe your URL should be https://apps.powerapps.com and after you login you can navigate to "/play/f1t75er8-03c9-4cc7-996d-6743cd7eac4a".

How to properly enable restful-keystone endpoint for model

Assuming I have a model named "Project", the documentation for restful-keystone suggests it should be as easy as the following to enable an API endpoint for it.
exports = module.exports = function(app) {
app.get('/', routes.views.index);
app.get('/gallery', routes.views.gallery);
restful.expose({
Project: true
}).start();
};
However, when I start keystone I get the following:
Rest is not enabled for galleries
Rest is not enabled for projects
Rest is not enabled for users
Can anybody explain to me what is going on and how to get this to work?
Found the solution after some research:
https://github.com/d-pac/restful-keystone/pull/5
This problem only occurs on windows, as the urls use path.join().
Use this https://github.com/d-pac/restful-keystone/pull/5/commits/0d8cf0c1514bad810fbc2345114d913cfb1e921a patch to temporarily fix your problem.
Unfortunately the maintainer has not merged the pull request yet.

Grails using Google authentication with the Spring Security plugin

Has anybody managed to successfully combine Google authentication with Burt Beckwith's awesome Grails-based Spring Security plugin recently? I wanted to go down that path with Grails 2.4.3, and after some fooling around (and recompiling the donbeave version of the plugin at https://github.com/donbeave/grails-spring-security-oauth-google) I was able to find a combination of references that would compile and run together. I ended up adding the following lines to my BuildConfig.groovy:
compile ':spring-security-core:2.0-RC4'
compile ":spring-security-oauth:2.1.0-RC4"
compile ':spring-security-oauth-google:0.3.1'
I found, however, that the changes created by the initialization command “grails s2-init-oauth” don’t give me all the modifications that I need in order to move forward. I ended up adding a block to my config.groovy that looked like this:
oauth {
providers {
google {
api = org.grails.plugin.springsecurity.oauth.GoogleApi20
key = 'MY KEY'
secret = 'MY SECRET'
successUri = '/oauth/google/success'
failureUri = '/oauth/google/error'
callback = "${baseURL}/oauth/google/callback"
scope = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
}
}
}
These config definitions specify a callback in my code (referred to above as ./oauth/google/callback) which didn’t exist. After I brought in a controller from the recommended example (https://github.com/bagage/grails-google-authentification-example), substituted "/springSecurityOAuth/onSuccess" for "/oauth/google/callback", (and registered by redirect URL through the Google Developers Console) I found that my onSuccess method was indeed being called, but the data structures referenced in the controller were wrong, and it seemed as if I would need to largely rewrite the controller logic in order to get everything working. I have to assume that other people want to accomplish Google-based authentication in the same way that I do. Is there an complete operational example somewhere? Or can someone tell me where I’ve gone wrong in my attempt to utilize the standard plug-ins? Thanks for any assistance.
You need to use spring security oauth plugin also. Please refer here https://github.com/cazacugmihai/grails-spring-security-oauth,
When you click on button, it hits the authenticate action inside Oauth controller which gets
authentication()
url of the google. After successful authentication, it hits callback() action Of Oauth controller which then redirects to onSuccess() action of SpringSecurityOauthController which then saves the info to OAuthId domain and finally redirects to the successUri given in config.

Meteor: setup accounts-github not working

I'm trying to setup authentication using github.
I followed the documentation. I've installed the packages:
$> meteor add accounts-github
$> meteor add service-configuration
And my code in server/github.js looks like:
ServiceConfiguration.configurations.remove({
service: "github"
});
ServiceConfiguration.configurations.insert({
service: "github",
clientId: '****',
secret: '*************'
});
Meteor.loginWithGithub({
requestPermissions: ['user', 'public_repo']
}, function (err) {
if (err)
Session.set('errorMessage', err.reason || 'Unknown error');
});
When I start meteor now I get the following error:
/Users/me/.meteor/tools/5bf1690853/lib/node_modules/fibers/future.js:173
throw(ex);
^
TypeError: Object #<Object> has no method 'loginWithGithub'
at app/server/github.js:11:8
at app/server/github.js:18:3
....
So it seems the Meteor object doesn't have the loginWithGithub method. Any suggestions why?
You are running the code in the /server directory of your app.
Usually you call this code from the web browser to make Meteor display the Github OAuth login dialog.
This is not available on the server since its only meant to work on the browser side. This is why you see this error.
You would usually fire Meteor.loginWithGithub() in the event listener for when they click a button or some UI element to begin the login process.
Another thing to keep in mind is Session (Session.get, Session.set, etc) only work on the client too.
To see which methods run where use the Meteor documentation. In the top corner of each method it shows where the code can run: Client, Server or Anywhere.