Skip to content
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 DocumentFragment XPath evaluate #1242

Merged
merged 8 commits into from Mar 14, 2024
Merged

Fix DocumentFragment XPath evaluate #1242

merged 8 commits into from Mar 14, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Mar 12, 2024

What?

This adds javascript code to convert a DocumentFragment into a Document.

Why?

DocumentFragments do not implement evaluate and so do not work with XPath selectors. When a DocumentFragment is encountered it will convert that to a Document so that evalaute with XPath selectors can be performed.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates: #1243

If the error is not caught, the polling doesn't early exit and can lead
to unexpected time outs with no context or errors on what went wrong.
@ankur22 ankur22 marked this pull request as draft March 13, 2024 09:13
XPath and evaluate are not available on DocumentFragments. This change
adds a function to allow the DocumentFragment to be converted into a
document and then be able to run the XPath evaluate against it.
When a DocumentFragment is found in XPathQueryEngine, convert it to a
document first before running evaluate with XPath against it. evaluate
and XPath do not work on DocumentFragments.
@ankur22 ankur22 marked this pull request as ready for review March 13, 2024 12:01
@ankur22 ankur22 requested a review from inancgumus March 13, 2024 12:01
tests/page_test.go Outdated Show resolved Hide resolved
@ankur22 ankur22 force-pushed the fix/doc-fragment-evaluate branch 3 times, most recently from aef50c3 to 54f0579 Compare March 13, 2024 14:32
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Nice fix! Could you explain (or add comments) the changes to the injected_script.js? Can you help me understand the goals of these changes and how they all work? (I don't have specific questions to ask because I need some general guidance to understand it. I understand that we're "somehow" converting DocumentFragment to Document).

@ankur22
Copy link
Collaborator Author

ankur22 commented Mar 14, 2024

Nice fix! Could you explain (or add comments) the changes to the injected_script.js? Can you help me understand the goals of these changes and how they all work? (I don't have specific questions to ask because I need some general guidance to understand it. I understand that we're "somehow" converting DocumentFragment to Document).

I've tried to tidy up the comments so that it makes a bit more sense, as well as adding more context. The details on the errors can be found in the issue itself (including the comments). Let me know if this helps or not.

Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

Thanks for the great explanations 🙇 Now, it's super clear for me.

common/js/injected_script.js Show resolved Hide resolved
@ankur22 ankur22 merged commit fe717a8 into main Mar 14, 2024
17 checks passed
@ankur22 ankur22 deleted the fix/doc-fragment-evaluate branch March 14, 2024 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants