feat(HikVision): add auto check jQuery plugin#777
Conversation
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdds an automatic check and conditional loading of a bundled jQuery plugin for the HikVision video component’s initialization script to ensure jQuery is available before plugin usage. Sequence diagram for HikVision init script loading with conditional jQuerysequenceDiagram
participant Browser
participant HikVisionScript as HikVision_init
participant ScriptLoader as addScript
Browser->>HikVisionScript: init(id)
activate HikVisionScript
HikVisionScript->>ScriptLoader: addScript(./_content/BootstrapBlazor.HikVision/jsencrypt.min.js)
ScriptLoader-->>HikVisionScript: script loaded
HikVisionScript->>ScriptLoader: addScript(./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js)
ScriptLoader-->>HikVisionScript: script loaded
HikVisionScript->>ScriptLoader: addScript(./_content/BootstrapBlazor.HikVision/webVideoCtrl.js)
ScriptLoader-->>HikVisionScript: script loaded
HikVisionScript->>Browser: check window.$
alt jQuery_not_present
HikVisionScript->>ScriptLoader: addScript(./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js)
ScriptLoader-->>HikVisionScript: script loaded
end
HikVisionScript->>Browser: document.getElementById(id)
Browser-->>HikVisionScript: element or null
HikVisionScript-->>Browser: return (continue initialization if element exists)
deactivate HikVisionScript
Flow diagram for HikVision init jQuery auto-check logicflowchart TD
A["init(id) called"] --> B["Load jsencrypt.min.js via addScript"]
B --> C["Load jsVideoPlugin-1.0.0.min.js via addScript"]
C --> D["Load webVideoCtrl.js via addScript"]
D --> E["window.$ is undefined?"]
E -- Yes --> F["Load jquery-1.7.1.min.js via addScript"]
F --> G["Get element by id"]
E -- No --> G["Get element by id"]
G --> H["element is null?"]
H -- Yes --> I["Return and stop"]
H -- No --> J["Continue HikVision video initialization"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider loading
jquery-1.7.1.min.jsbeforejsVideoPlugin-1.0.0.min.jsandwebVideoCtrl.jsif those scripts assume$is available at load time, otherwise they may initialize incorrectly on pages without jQuery. - The jQuery presence check only looks at
window.$; you may also want to checkwindow.jQueryto avoid reloading jQuery in environments where$is aliased or not exposed.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider loading `jquery-1.7.1.min.js` before `jsVideoPlugin-1.0.0.min.js` and `webVideoCtrl.js` if those scripts assume `$` is available at load time, otherwise they may initialize incorrectly on pages without jQuery.
- The jQuery presence check only looks at `window.$`; you may also want to check `window.jQuery` to avoid reloading jQuery in environments where `$` is aliased or not exposed.
## Individual Comments
### Comment 1
<location> `src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js:9` </location>
<code_context>
await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js');
+ if (window.$ === void 0) {
+ await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js');
+ }
+
</code_context>
<issue_to_address>
**🚨 issue (security):** Loading jQuery 1.7.1 introduces potential security and compatibility concerns; consider a more recent version if possible.
jQuery 1.7.1 has known security issues and poor support in modern browsers. If you can change this dependency, please use a supported jQuery version (1.x LTS or newer) that remains compatible with the HikVision plugin to avoid relying on a vulnerable library.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js'); | ||
|
|
||
| if (window.$ === void 0) { | ||
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js'); |
There was a problem hiding this comment.
🚨 issue (security): Loading jQuery 1.7.1 introduces potential security and compatibility concerns; consider a more recent version if possible.
jQuery 1.7.1 has known security issues and poor support in modern browsers. If you can change this dependency, please use a supported jQuery version (1.x LTS or newer) that remains compatible with the HikVision plugin to avoid relying on a vulnerable library.
There was a problem hiding this comment.
Pull request overview
This PR adds functionality to automatically detect and load jQuery if it's not already present on the page, addressing issue #776 where the HikVision component failed when jQuery wasn't globally available.
Key Changes:
- Added conditional jQuery loading to ensure the HikVision plugin's dependencies are met
- Checks for jQuery existence using
window.$before dynamically loading jQuery 1.7.1
Comments suppressed due to low confidence (1)
src/components/BootstrapBlazor.HikVision/wwwroot/hikvision.js:224
- Unused variable szDeviceIdentify.
const { iWndIndex, szDeviceIdentify } = vision;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await addScript('./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js'); | ||
| await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js'); | ||
|
|
||
| if (window.$ === void 0) { | ||
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js'); | ||
| } |
There was a problem hiding this comment.
The jQuery check and loading happens after loading webVideoCtrl.js, but webVideoCtrl.js depends on jQuery. The file contains extensive jQuery usage (e.g., $, $("#"+id), $.each, etc.). This creates a race condition where webVideoCtrl.js will execute before jQuery is available, causing runtime errors.
jQuery should be loaded first, before any scripts that depend on it. Move the jQuery check and loading to lines 5-7, before the jsVideoPlugin and webVideoCtrl scripts.
| await addScript('./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js'); | |
| await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js'); | |
| if (window.$ === void 0) { | |
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js'); | |
| } | |
| if (window.$ === void 0) { | |
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js'); | |
| } | |
| await addScript('./_content/BootstrapBlazor.HikVision/jsVideoPlugin-1.0.0.min.js'); | |
| await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js'); |
| await addScript('./_content/BootstrapBlazor.HikVision/webVideoCtrl.js'); | ||
|
|
||
| if (window.$ === void 0) { | ||
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js'); |
There was a problem hiding this comment.
jQuery 1.7.1 is from 2011 and has multiple known security vulnerabilities (CVE-2012-6708, CVE-2015-9251, CVE-2019-11358, CVE-2020-11022, CVE-2020-11023). Consider upgrading to jQuery 3.7.1 or later, which includes security fixes and is still compatible with legacy code. If the HikVision plugin requires this specific old version, document this requirement and the security implications.
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-1.7.1.min.js'); | |
| // Updated to jQuery 3.7.1 for security reasons (CVE-2012-6708, CVE-2015-9251, CVE-2019-11358, CVE-2020-11022, CVE-2020-11023) | |
| // If the HikVision plugin fails with this version, revert to 1.7.1 and document the risk. | |
| await addScript('./_content/BootstrapBlazor.HikVision/jquery-3.7.1.min.js'); |
Link issues
fixes #776
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
New Features: