-
Notifications
You must be signed in to change notification settings - Fork 342
IOS fix: only insert Kapa.ai script for newer versions of IOS #3803
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
Open
Blargian
wants to merge
8
commits into
ClickHouse:main
Choose a base branch
from
Blargian:fix_kapa_issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b7f213
only insert kapa script for newer versions of IOS
Blargian e9154f9
Add error handling
Blargian 53b874f
test blanket disable of widget on ios
Blargian fdaf3b2
disable kapa completely to test
Blargian d1450f7
Update kapa_widget.js
Blargian 1295136
Delete scripts/settings/functions_arithmetic.sql
Blargian 7f36e5c
Update docusaurus.config.en.js
Blargian a1e1ec1
Update kapa_widget.js
Blargian 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 hidden or 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 hidden or 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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,73 @@ | ||||||
function insertKapaWidget() { | ||||||
// Check if user agent is iOS 16.4 or lower | ||||||
function isOldiOS() { | ||||||
const ua = navigator.userAgent; | ||||||
|
||||||
// Check if it's an iOS device | ||||||
const isIOS = /iPad|iPhone/.test(ua); | ||||||
|
||||||
if (isIOS) { | ||||||
// Regex to capture major version and optionally minor version. | ||||||
// Examples: "OS 16_4" (major: 16, minor: 4), "OS 16" (major: 16, minor: defaults to 0) | ||||||
const iosVersionMatch = ua.match(/OS (\d+)(?:_(\d+))?/); | ||||||
|
||||||
if (iosVersionMatch) { | ||||||
const majorVersion = parseInt(iosVersionMatch[1], 10); | ||||||
let minorVersion = 0; // Default minor version to 0 | ||||||
|
||||||
// If minor version (group 2) was captured in the regex | ||||||
if (iosVersionMatch[2]) { | ||||||
minorVersion = parseInt(iosVersionMatch[2], 10); | ||||||
// Fallback if parsing somehow still results in NaN (though \d+ should prevent this for a captured group) | ||||||
if (isNaN(minorVersion)) { | ||||||
minorVersion = 0; | ||||||
} | ||||||
} | ||||||
|
||||||
// Return true if iOS version is 16.4 or lower | ||||||
// (major < 16) OR (major == 16 AND minor <= 4) | ||||||
return majorVersion < 16 || (majorVersion === 16 && minorVersion <= 4); | ||||||
} else { | ||||||
// It's an iOS device, but we couldn't parse the OS version string using the regex. | ||||||
// To be safe and prevent loading the widget on a potentially old/unsupported iOS version, | ||||||
// assume it IS an "old iOS" in this scenario. | ||||||
console.warn('Kapa widget: iOS device detected, but OS version parsing failed. Assuming old iOS to prevent loading.'); | ||||||
return true; // Treat as "old" if parsing fails for an iOS device | ||||||
} | ||||||
} | ||||||
|
||||||
// Not an iOS device, or parsing failed and we're not treating it as old by default (if the above 'else' was different) | ||||||
return false; | ||||||
} | ||||||
|
||||||
// Only insert script if not running on older iOS as Kapa does not support it (using a look behind regex) | ||||||
if (!isOldiOS()) { | ||||||
const script = document.createElement('script'); | ||||||
script.src = 'https://widget.kapa.ai/kapa-widget.bundle.js'; | ||||||
script.async = true; | ||||||
script.defer = true; | ||||||
script.setAttribute('data-website-id', 'c0b5f156-1e92-49df-8252-adacc9feb21b'); | ||||||
script.setAttribute('data-project-name', 'ClickHouse'); | ||||||
script.setAttribute('data-project-color', '#151515'); | ||||||
script.setAttribute('data-project-logo', 'https://avatars.githubusercontent.com/u/54801242?s=200&v=4'); | ||||||
script.setAttribute('data-modal-disclaimer', 'This is a custom LLM for ClickHouse with access to all developer documentation, open GitHub Issues, YouTube videos, and resolved StackOverflow posts. Please note that answers are generated by AI and may not be fully accurate, so please use your best judgement.'); | ||||||
script.setAttribute('data-modal-example-questions', 'How to speed up queries?,How to use materialized views?'); | ||||||
script.setAttribute('data-kapa-branding-hide', 'true'); | ||||||
|
||||||
document.head.appendChild(script); | ||||||
console.log('Kapa widget script added successfully'); | ||||||
} else { | ||||||
console.log('Kapa widget not added: detected iOS 16.4 or lower'); | ||||||
} | ||||||
} | ||||||
|
||||||
// Run the function when DOM is fully loaded | ||||||
if (document.readyState === 'loading') { | ||||||
document.addEventListener('DOMContentLoaded', insertKapaWidget); | ||||||
} else { | ||||||
try { | ||||||
insertKapaWidget(); | ||||||
} catch (e) { | ||||||
console.log("An error occured while trying to load the Kapa.ai widget:", e); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix typo in the log message: change
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
} |
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.
[nitpick] Consider extracting
16
and4
into named constants (e.g.,MIN_SUPPORTED_MAJOR
,MIN_SUPPORTED_MINOR
) to improve readability and simplify future version updates.Copilot uses AI. Check for mistakes.