在调试模式下运行Visual Studio 2022时,可以安装PWA服务工作者

发布于 2025-01-24 17:23:57 字数 1128 浏览 2 评论 0 原文

我正在研究Blazor WebAssembly是否是即将到来的Progressive Web应用程序(PWA)项目的良好体系结构。

在Visual Studio 2022中,我创建了一个“ Blazor Web Assembly应用程序”,然后检查“ .NET 6.0 LTS”,“为HTTPS”,“ ASP.NET Core Hosted”和“ Progressive Web Application”。然后,我“ F5”以调试模式运行该项目。

然后在浏览器中(我使用的是Chrome 101.0.4951.41,但Edge做同样的事情),F12转到开发人员工具并选择“应用程序”选项卡。我期望看到服务工作者已安装,但状态为“#0尝试安装”。

我对PWA有一个过分的熟悉,但我以前从未看到过,很困惑。

我注意到,当开发人员工具打开并刷新页面时,它一直转到“ Souces”选项卡。它显示了我通常会忽略的WASM/.NET噪声的“ dotnet.6.4.4.slzlks63yx.js”。

然后我单击漂亮的打印“ {}”,并用“调试器”揭示以下内容;线突出显示...

“在此处输入图像描述”

我试图防止Chrome在,但这没有任何区别。

我已经关闭了热重新加载,但这又无效。

有效的是,如果您在不调试的情况下启动应用程序(CTRL-F5)。服务工作者从预期开始。

这是一个错误吗?这是预期的行为吗?我做错了吗?

提前致谢。

I am investigating whether Blazor WebAssembly is a good architecture for an upcoming Progressive Web Application (PWA) project.

In Visual Studio 2022, I create a "Blazor Web Assembly App", and check ".NET 6.0 LTS", "Configure for HTTPS", "ASP.NET Core Hosted" and "Progressive Web Application". I then "F5" to run the project in debug mode.

Then in the browser (I am using Chrome 101.0.4951.41 but Edge does the same thing), F12 to go to the Developer Tools and select the Application tab. I was expecting to see the Service Worker installed but the status is "#0 trying to install".

I have a passing familiarity with PWAs but I have not see this before and was very confused.

I noticed that when the Developer Tools was opened and I refreshed the page, it kept going to the "Souces" tab. It was showing "dotnet.6.0.4.slzlks63yx.js" with WASM/.Net noise that I generally ignore.

enter image description here

I then click on the Pretty Print "{}" and it reveals the following with the "debugger;" line highlighted...

enter image description here

I have attempted to prevent Chrome from stopping at Debugger statements as per how to totally ignore 'debugger' statement in chrome? but this did not make any difference.

I have turned off hot reloading but again this did not work.

What does work, is if you start the app without Debugging (Ctrl-F5). The service worker starts as expected.

Is this a bug? Is this expected behaviour? Am I doing something wrong?

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜深人未静 2025-01-31 17:23:57

默认情况下,只能使用已发布的版本来安装Glazor WASM的PWA侧。这是为了防止调试错误的代码,因为它使用的是缓存元素而不是新鲜编译的代码。

如果您在项目中查看,您将找到service-worker.js文件,并嵌套其中,您可以使用service-worker.parpared.js文件,其中包含PWA CACHESTARME所需的所有魔术。您可以将其移至普通文件中...但是如果使用它,请注意缓存刷新或缺乏的潜在错误和可能的错误。

By default the PWA side of Blazor Wasm can only be installed using a published version. This is to prevent debugging wrong code because it is using cache element instead of freshly compiled code.

If you look in your project, you will find the service-worker.js file, and nested with it, you have a service-worker.published.js file with all the magic needed for PWA cache install. You can move it to the normal file... But be aware of potential and probable bugs from cache refresh or lack of, if you use it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文