简体   繁体   English

如何关闭工作箱浏览器控制台消息?

[英]How can I turn off the workbox browser console messages?

Very simply, I would like to disable the display of the repeated workbox messages that appear in my browser console while I am debugging.很简单,我想在调试时禁用浏览器控制台中出现的重复工作箱消息的显示。 For instance, I don't need to see:例如,我不需要看到:

WorkBox: Using NetworkFirst to respond to '/fonts/KFOlCnqEu92Fr1MmEU9fBBc-.woff'

It clutters my FireFox console and it is something I dislike very much.它弄乱了我的 FireFox 控制台,这是我非常不喜欢的东西。 If you like it, fine, please don't try to change my mind about the benefit of such useless (to me) messages.如果你喜欢它,好吧,请不要试图改变我对这些无用(对我来说)消息的好处的看法。 Do you know how to turn it off?你知道怎么关掉吗? For info sake, I am using Quasar and Vue to create a SPA - not even a PWA.为了提供信息,我使用 Quasar 和 Vue 来创建 SPA - 甚至不是 PWA。 Thanks.谢谢。

You can use workbox.setConfig({ debug: false });您可以使用workbox.setConfig({ debug: false }); in order to use production build and remove extra logging, otherwise adjust your web console log level filtering accordingly.为了使用生产构建并删除额外的日志记录,否则相应地调整您的 Web 控制台日志级别过滤。

Doc : https://developers.google.com/web/tools/workbox/guides/troubleshoot-and-debug文档: https : //developers.google.com/web/tools/workbox/guides/troubleshoot-and-debug

You add this setting in your service worker definition file, after the import.导入后,您可以在 Service Worker 定义文件中添加此设置。 For example:例如:

importScripts(`https://storage.googleapis.com/workbox-cdn/releases/4.3.1/workbox-sw.js`);
if (workbox) {
    console.log(`Yay! Workbox is loaded 😁`);
} else {
    console.log(`Boo! Workbox didn't load 😬`);
}
// Switch debug logging on/off here. Default is on in dev and off in prod.
workbox.setConfig({debug: false});

For more information on this see https://developers.google.com/web/tools/workbox/guides/configure-workbox#configure_debug_builds_vs_production_builds有关这方面的更多信息,请参阅https://developers.google.com/web/tools/workbox/guides/configure-workbox#configure_debug_builds_vs_production_builds

Simply add self.__WB_DISABLE_DEV_LOGS = true at the top of your service worker ( sw.js ) file.只需在 Service Worker ( sw.js ) 文件的顶部添加self.__WB_DISABLE_DEV_LOGS = true sw.js

Contrarily to what answers posted here say, the solution is not:与此处发布的答案相反,解决方案不是:

  • to unregister your service worker to get rid of the messages.取消注册您的服务工作者以摆脱消息。 Your app may need it to run properly您的应用可能需要它才能正常运行
  • to add workbox.setConfig({debug: false}) unless knowing what it does:添加workbox.setConfig({debug: false})除非知道它的作用:
    it switches between a production build and a debug build.它在生产版本和调试版本之间切换。 workbox automatically selects the debug build when running on localhost .localhost 上运行时, workbox自动选择调试版本。

对我来说:控制台 -> 应用程序选项卡 -> 服务工作者 -> sw.js 注销

Thanks to the answer provided by Antonina K, I was able to locate an answer for FireFox.感谢 Antonina K 提供的答案,我能够找到 FireFox 的答案。 In case anyone else needs this.万一其他人需要这个。 As Antonina mentioned, in Chrome, the console has an application tab that has references to all the service workers used by the browser.正如 Antonina 所提到的,在 Chrome 中,控制台有一个应用程序选项卡,其中包含对浏览器使用的所有服务工作线程的引用。 FireFox does not have the tab (or, at least my version does not). FireFox 没有选项卡(或者,至少我的版本没有)。 In FireFox, open a new tab and place about:serviceworkers in the address bar.在 FireFox 中,打开一个新选项卡并将 about:serviceworkers 放在地址栏中。 Scroll through the list to find the workbox service worker.滚动列表以查找工作箱服务工作者。 For me, it was listed as localhost:8080.对我来说,它被列为 localhost:8080。 I deregistered that worker and I no longer see the multitude of workbox messages in my console.我取消了该工作人员的注册,并且不再在控制台中看到大量工作箱消息。 I can finally debug my app again!我终于可以再次调试我的应用程序了! Here is the link that I referenced to fix the problem: Manage Service Workers in FireFox and Chrome这是我引用的解决问题的链接: 在 FireFox 和 Chrome 中管理服务工作者

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM