Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions jsbridge/src/main/java/com/apkfuns/jsbridge/JsBridgeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ private JsModule getModule(String moduleName) {

private String getInjectJsString() {
StringBuilder builder = new StringBuilder();
// Issue #35: guard the whole injection so OnJsBridgeReady
// fires only once per JS context. A fresh page load starts
// with window.<protocol> undefined and gets the bridge set
// up exactly once. Re-injection on the same context (for
// example onPageFinished firing multiple times, or sub
// frames triggering an extra inject call) becomes a no-op.
builder.append("if(!window.").append(newProtocol).append("){");
builder.append("var ").append(className).append("=function(){");
// 注入通用方法
Comment on lines +223 to 225
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR description mentions clean() sets window.<protocol> back to undefined, but the implementation uses <protocol>=undefined; (no window.). To avoid confusion and keep the contract clear, update either the description or the code so both refer to the same form (window.<protocol> vs global identifier).

Copilot uses AI. Check for mistakes.
builder.append(JBUtilMethodFactory.getUtilMethods(newLoadReadyMethod));
Expand Down Expand Up @@ -255,6 +262,7 @@ private String getInjectJsString() {
builder.append("};");
builder.append("window." + newProtocol + "=new " + className + "();");
builder.append(newProtocol + ".OnJsBridgeReady();");
builder.append("}");
return builder.toString();
}

Expand Down
Loading