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 bug where headings get duplicated #10

Merged
merged 1 commit into from
Feb 14, 2022
Merged

Fix bug where headings get duplicated #10

merged 1 commit into from
Feb 14, 2022

Conversation

khiga8
Copy link
Owner

@khiga8 khiga8 commented Feb 14, 2022

This PR fixes a bug where the heading levels get appended multiple times to a page when using the back and forth button, or when clicking the tab of a page we're already on multiple times.

To prevent this, we should clean up the DOM whenever onHistoryStateUpdated events are fired (indicating page navigation). We do not need to do this on initial page load.

Screenshot of bug

Screen shot of bug where heading level text appears 3 times after the heading level

});

appendAccessibilityInfo();
Copy link
Owner Author

Choose a reason for hiding this comment

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

This method will run on initial page load after DOM is complete.

From Content Script Chrome Docs:

Content scripts running at "document_idle" do not need to listen for the window.onload event, they are guaranteed to run after the DOM is complete. If a script definitely needs to run after window.onload, the extension can check if onload has already fired by using the document.readyState property.

Comment on lines +38 to +41
chrome.runtime.onMessage.addListener(async (message) => {
document.querySelectorAll(".github-a11y-img-caption").forEach(el => el.remove());
document.querySelectorAll(".github-a11y-heading-prefix").forEach(el => el.remove());
appendAccessibilityInfo();
Copy link
Owner Author

Choose a reason for hiding this comment

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

We add event listener to listen for navigation events and clean up DOM & append elements again.

@khiga8 khiga8 merged commit 36b1371 into main Feb 14, 2022
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.

1 participant