-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Fixed the issue that the TCP connection was interrupted when setting a proxy #9708
Closed
Zuoqiu-Yingyi
wants to merge
3
commits into
siyuan-note:dev
from
Zuoqiu-Yingyi:fix/electron-set-proxy
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
// https://github.com/siyuan-note/siyuan/pull/8012 | ||
export const registerServiceWorker = (scriptURL: string, scope = "/", workerType: WorkerType = "module") => { | ||
if (!("serviceWorker" in navigator) || typeof (navigator.serviceWorker) === "undefined" || | ||
!("caches" in window) || !("fetch" in window)) { | ||
return; | ||
export const registerServiceWorker = async (scriptURL: string, scope = "/", workerType: WorkerType = "module") => { | ||
if (("serviceWorker" in window.navigator) && ("caches" in window) && ("fetch" in window)) { | ||
try { | ||
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration | ||
const registration = await window.navigator.serviceWorker.register(scriptURL, { | ||
scope, | ||
type: workerType, | ||
}); | ||
await registration.update(); | ||
return true; | ||
} catch (error) { | ||
console.debug(`Registration failed with ${error}`); | ||
return false; | ||
} | ||
} | ||
// REF https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration | ||
window.navigator.serviceWorker | ||
.register(scriptURL, { | ||
scope, | ||
type: workerType, | ||
}).then(registration => { | ||
registration.update(); | ||
}).catch(e => { | ||
console.debug(`Registration failed with ${e}`); | ||
}); | ||
return false; | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
和 proxy 没有关系的代码麻烦不要提交。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是为了避免加载 service-worker 时对现有请求造成不可预期的影响,是相关的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个只有在浏览器端和移动端使用,和 electron 的 setProxy 无关。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在使用中发现在 electron 中使用
<iframe>
或<webview>
标签访问/stage/build/desktop/
与/stage/build/mobile/
也会触发 service-workerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
registerServiceWorker 这个好像还是你 PR 的,是不是这些情况排查漏了。这个问题应该从源头上改进,而不是对错误进行兼容。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
原有实现暂时也未出现问题, 这里的改进是为了消除不确定性
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前的 registerServiceWorker 为什么要在 electron 中运行?感觉是没有必要的。不是出现问题才是有 bug。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不是
registerServiceWorker
要在 electron 中运行, 而是无法完全阻止registerServiceWorker
在 electron 中运行, 因为<iframe>
与<webview>
的上下文可能是完全隔离的不过我刚刚有一个想法, 在 electron 环境中检测到 service-worker 后可以自动注销该 worker, 我先去测试一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Vanessa219
提交了一个解决方案: 在启动时从桌面端与移动端 App 中注销当前存在的 service-worker
详情请参考 36bad6c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能不能不要搅和在这个 issue 里面呀 😭