-
Notifications
You must be signed in to change notification settings - Fork 443
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
fix: use window.location.origin
as baseUrl for scrapeList
#228
Conversation
WalkthroughThe changes in this pull request primarily involve updates to the Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Works correctly for a run.
Issue persists during output preview
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
maxun-core/src/browserSide/scraper.js (2)
286-288
: Add error handling for malformed URLsThe URL resolution is correctly implemented, but consider adding try-catch block to handle malformed URLs gracefully.
// Handle relative 'src' URLs const src = fieldElement.getAttribute('src'); -record[label] = src ? new URL(src, window.location.origin).href : null; +record[label] = src ? (() => { + try { + return new URL(src, window.location.origin).href; + } catch (e) { + console.warn(`Invalid URL found for ${label}: ${src}`); + return null; + } +})() : null;
292-292
: Reduce code duplication in URL handlingThe URL resolution logic is duplicated between 'src' and 'href' handling. Consider extracting it into a helper function.
+const resolveRelativeUrl = (url, label) => { + if (!url) return null; + try { + return new URL(url, window.location.origin).href; + } catch (e) { + console.warn(`Invalid URL found for ${label}: ${url}`); + return null; + } +}; // In the scrapeList function: -record[label] = src ? new URL(src, window.location.origin).href : null; +record[label] = resolveRelativeUrl(src, label); -record[label] = href ? new URL(href, window.location.origin).href : null; +record[label] = resolveRelativeUrl(href, label);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
maxun-core/src/browserSide/scraper.js
(2 hunks)
🔇 Additional comments (1)
maxun-core/src/browserSide/scraper.js (1)
286-288
: LGTM! Changes successfully address the baseUrl ReferenceError
The implementation correctly uses window.location.origin
for URL resolution, effectively fixing the undefined baseUrl
reference issue. The solution is robust and follows web standards for URL handling.
Also applies to: 292-292
fixes #227
Summary by CodeRabbit
Bug Fixes
src
andhref
attributes during scraping, ensuring accurate URL resolution against the current window origin.Style