-
Notifications
You must be signed in to change notification settings - Fork 19
fix: prevent INJECT_DEBUG js script multiple execution #100
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
Conversation
| const originalConsoleLog = console.log; | ||
| const originalConsoleError = console.error; | ||
| const originalConsoleWarn = console.warn; | ||
| if (!window["webview_bridge_debug_injected"]) { |
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.
| if (!window["webview_bridge_debug_injected"]) { | |
| if (window["webview_bridge_debug_injected"]) { | |
| return; | |
| } |
how about use early return ?
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.
and It’s a minor detail, but as shown above, generating a random value and using it can be a good idea.
Although the possibility is low, storing it on the window object can cause name collisions.
import { createRandomId } from "@webview-bridge/utils";
const randomId = createRandomId();
export const INJECT_DEBUG = `
{
const originalConsoleLog = console.log;
const originalConsoleError = console.error;
const originalConsoleWarn = console.warn;
if (!window["webview_bridge_debug_injected_${randomId}"]) { // <<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.
Although the possibility is low, storing it on the window object can cause name collisions.
I was worried about naming collisions too, but couldn't think of a way around it.
This seems like the perfect solution.
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.
What do you think about prefix webview_bridge_debug_injected_?
If there is a naming convention within the project, I will follow it.
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.
__bridge_debug_injected_{randomId} 👍
- Use early return - Append random id after injection detect key for prevent collision
|
Here you go 😉 |
|
Thanks !! |
FIx #99
I tested it locally but not sure there aren't potential issue