-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FCM integration/service-worker registration #1481
Comments
|
First, I think it can be both. Why I think it's more of a feature request is I need an API to merge a custom service worker to the one Vue provides. There's a I can't tell whether it should be a bug report or feature request because
Second, runnable reproduction is simple enough I thought I didn't need to explicitly provide any. The replication step is simple:
Third, I'm not even asking for a solution to solve a specific problem for myself, I asked for a way to register a service worker with or without using For const registration = await navigator.serviceWorker.register(`${process.env.BASE_URL}firebase-messaging-sw.js`)
messaging.useServiceWorker(registration) My purpose was to illustrate what I need was not merging multiple service workers, but I also needed to make use of the As for the Fourth, I found it disappointing that instead of at least pointing me to the right direction to find a solution myself, you are more fixated on whether it's a bug report or feature request because a strict policy triumphs everything. Before I opened an issue, I already looked at all the relevant issues here:
I even asked a question on StackOverflow and included a discussion from vuejs-templates here. I'm not asking for handouts, I just want to make the app work, and opening issue here is what I thought I had to after trying different things for two days. Yet because of a "strict" policy I got shunned down. Thank you very much. |
You have it. You just misunderstood the documentation, which, I have no problem admitting, has to be refined until we leave beta. You asked for a hint:
If you need more help, please use the appropriate channels, like the forum where I'm very active.
We explain in detail why we ask for runnable reproductions on new-issue.vuejs.org, which you probably have read. This situation is not an exception. You might think that it's easy to repoduce with the things you shared, but we have so, so many issues where people thinbk they showed us everything requried, only to find out after much work that the problem was in some other change they did, or forgot to show/share. We simply refuse to put in this unnecessary work and waste time with it.
I understand that you are a bit frustrated about being stuck, and I'm sorry for that. But in order to keep the work that we do manageabe, we have a strict process in place. You filled out the issue template, in which we explain there we have both a dedicated forum and a dedicated chat, which should be used to address questions about usage. We are active in both. You ignored that and opened and issue without trying these sources first, because you didn't get a reply on SO within a few minutes to an hour (I compared timestamps, you did both posts 7-8 hours ago). |
A strict policy is what keeps the project manageable. If we make an exception for everyone (and everyone will have an excuse somehow), we'd be just replying to issues all day without getting any real work done. |
Did all of this, after a build, it can not find service-worker.js |
Feel free to start a topic on forum.vuejs.org and we 'll see how to help. No support in issues. |
As long as an explicit registration of the service worker is required, what @LinusBorg said doesn't work. I finally sort of made it work by ditching First, in module.exports = {
pwa: {
// configure the workbox plugin
workboxPluginMode: 'InjectManifest',
workboxOptions: {
swSrc: 'src/firebase-messaging-sw.js'
// ...other Workbox options...
}
} The original service worker Vue uses will be injected into your service worker later. Therefore, all you need to do is register your service worker like how you used to:
After the changes, the only differences I found were Chrome wouldn't automatically pop up and ask if I want to add my app to home screen. And after adding the app to the home screen, there's a chrome icon on it. Note that I've already tried registering Firebase inside register(`${process.env.BASE_URL}firebase-messaging-sw.js`, {
ready () {
console.log(
'App is being served from cache by a service worker.\n' +
'For more details, visit https://goo.gl/AFskqB'
)
},
registered (registration) {
// MAKE USE OF REGISTRATION HERE
},
// ...
}) I'm listing the solution here because I basically found a workable solution, starting a topic on forum.vuejs.org and post the solution doesn't seem too necessary. |
Thanks for sharing this. I'm bit suprised that in your case, you say that no Because according to the docs of the workbox-plugin, unless you set And that's what my recommendation was reyling upon Your code snippet mentions Did you by any chance set |
@LinusBorg I just tested it and the generated filename is not Should I just add |
Thanks for the feedback. We probably should test this a bit more and adjust the generator that creates the |
im finding this after tons of digging on how to answer the same question, there is zero documentation on what to do with this, and if anyone could just post a few code examples of grabbing the registration object ( or whatever ) and doing something productive with it ( like sending a push notification or caching something ) they'd be a vuejs hero. moved this to a stack overflow post: https://stackoverflow.com/questions/51214220/vue-cli-3-how-to-use-the-official-pwa-plugin-service-worker |
Let's do the following: I'll walk you through the path of the documentation as I see it to answer your questions, trying to acknowledge missing pieces along the way, and you comment on that, adding information about what else is missing in your opinion, what could be made more clear, and what you may have missed when you asked your original question because said path wasn't clear. That way, we can identify spots where we have to improve the docs. Preface:I don't think that it's the job of the vue-cli documentation to explain
What we should do:
Walkthrough
So let's assume you
The question that you are left with, and that you asked here, is how to interact with this serviceworker. I think we should:
A With that Object, you get access to all of the serviceworker features, and I think we stop exactly here. As expained in the preface, teaching how to use service-workers is out of scope for vue-cli. Maybe the community steps in and writes a nice guide about cools stuff to do with your own service worker for our cookbook or their own blog, and we can then link to it, but other than that, educating yourself is your own responsibility. Thougths? |
Yes I think you hit the nail on the head, including pointing me in a solid direction to go from here. Thank you. To answer your comment: yes, I did read through all of those documents already. What you just said:
is excellent, it answers the question, but is by no means as self explanatory as you make it out to be. maybe I'll upload some solutions myself once I work through this. |
Note that "can't do anything" might be a bit exaggerated - you still get acces to the same Registration object and all of its options. But since you can't add your own code to that service-worker, it is of limited usefulness imho.
That's more of a problem with the workbox documentation, isn't it? We also don't say a word about how to use typescript, eslint, jest, or any of the other tools that vue-cli adds for you, for good reason. I'm happy to add a small paragraph to the plugin's README (or accept a PR for one), but that must be it. |
I just read the part on the workbox doco that mentioned needing 'injectManifest' for any other PWA functionality. Its one of those moments where my eyes glaze over text and it just doesn't register in my mind what it really means -.- |
It looks like default swDest will have the same file name as swSrc in injectManifest mode only. |
@safu9 yep, that's why your dwfault implementation still works. |
I have similar problems, however I noticed that when is |
Through all these three steps, we can successfully create our own sw.js file in prodution mode.
Actually the sceond one may be the Webpack work flow problem,
but it really confuses me that how to make this work, |
@kevguy My solution after read all this: The file But. If you add configuration in your Anyway, I have a lot of doubts, for example. If I use |
hi guys, I also struggled with doing some extra things with custom service workers. Now I wrote a small guide on how to use Vue PWA with a custom service worker and how to get:
https://medium.com/@kobededecker/vue-pwa-example-298a8ea953c9 |
@LinusBorg Hi - are you able to explain what the expected development process would be for this? Lets say I've added the following to a console.log('im here');
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {}); When we run -- That is all fine for production/testing it out BUT.... How are we meant to use the vue cli to develop this file efficiently? e.g. we have The only way I can get any form of it working is by running This obviously doesn't seem optimal - and I think maybe what many people are also struggling with as the docs don't currently explain the development process in the same way as it explains many of the others. What would you consider to be the solution to this? or a suggested process to have this working as efficiently as possible? Many thanks :) |
@gwaihir8 I don't understand why I can't register an event on self.addEventListener('notificationclick', function(event) {
console.log('notificationclick', notification)
var notification = event.notification;
}) |
@rstormsf Because the service-worker lives in a separate process and can't register browser events directly. Capture the event in the browser (easiest in the |
What problem does this feature solve?
I used
vue-cli
to create a Vue app for development and so far the experience has been great. However, I also wanted to add FCM support to it which requires me adding a service worker. I have been working on the integration for two days but I still don't know how to do it and register the service worker properly.I've tried adding a new service worker
firebase-messaging-sw.js
inside thepublic
folder and register it inApp.vue
usingwhich works but then I'll have two service workers.
Then I modified
vue.config.js
to use this service worker instead:Then I encounter errors like
The script has an unsupported MIME type ('text/html').
I've checked Workbox's guides, @vue/cli-plugin-pwa but I still can't make it work. Can someone show me how to do the integration, cause I really don't know how to do it.
This discussion seems really close to what I'm asking for (vuejs-templates/pwa#27).
I also asked the question on StackOverflow (https://stackoverflow.com/questions/50711933/vue-cli-3-and-firebase-service-worker-registration)
What does the proposed API look like?
I should be able to have a correct config to do FCM integration.
The text was updated successfully, but these errors were encountered: