Commit 5f3ad570 authored by Robert Knight's avatar Robert Knight

Make direct-link injection robust to URL fragment changes as the page loads.

Sites such as Medium and EBSCOHost modify the URL fragment as the page
loads, causing direct-link annotation ID fragments to be lost by the
time the app's init code runs.

When a tab's URL changes, extract the '#annotations' fragment and pass
it to the application as configuration info when the app is injected.
If the URL fragment is removed or replaced by client-side JS as the page
loads, the app will still get the original annotation ID that was
captured by the extension prior to the page load completing.

The direct-linked ID is remembered until the sidebar is successfully
injected, at which point it is cleared so that it is not re-used on the
next navigation within the tab.
parent 336db8c8
...@@ -33,6 +33,14 @@ function config(window_) { ...@@ -33,6 +33,14 @@ function config(window_) {
} }
} }
// Extract the direct linked ID from the URL.
//
// The Chrome extension or proxy may already have provided this config
// via a tag injected into the DOM, which avoids the problem where the page's
// JS rewrites the URL before Hypothesis loads.
//
// In environments where the config has not been injected into the DOM,
// we try to retrieve it from the URL here.
var directLinkedID = annotationIDs.extractIDFromURL(window_.location.href); var directLinkedID = annotationIDs.extractIDFromURL(window_.location.href);
if (directLinkedID) { if (directLinkedID) {
options.annotations = directLinkedID; options.annotations = directLinkedID;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment