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

Make tocbot work inside iframes #307

Merged
merged 3 commits into from
Aug 1, 2023
Merged

Conversation

felipemarcos
Copy link
Contributor

@felipemarcos felipemarcos commented Jul 31, 2023

Problem

Screenshot 2023-07-31 at 16 47 34

The instanceof window.HTMLElement statement returns false when inside an iframe element in very specific situations, this causes the script to stop working thus rendering a blank table of contents.

Solution

I've added instanceof window.parent.HTMLElement to check if an element was created by the parent document. This check only works in iframes in the same domain, so I wrapped it in a try-catch block to prevent errors.

@felipemarcos felipemarcos marked this pull request as ready for review July 31, 2023 20:27
@tscanlin
Copy link
Owner

tscanlin commented Aug 1, 2023

Thanks for the fix / PR!!

@tscanlin tscanlin merged commit 96f8de6 into tscanlin:master Aug 1, 2023
3 of 4 checks passed
@tscanlin
Copy link
Owner

tscanlin commented Aug 1, 2023

This should be published now. Thanks again!
📦 [email protected]

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.

2 participants