It seem that document.contains is to check whether
the node is removed, but not to consider about the
shadow root.
The isConnected property mean whether the node is
connect to a document or a shadow root that
connected to the root document.
It is enough to check whether the document is
removed.
The previous method skipped too many or too few hint names in some
cases; the new one should skip the optimal number in all cases.
If the number of hints was equal to the number of hint characters, then
a hint name would be skipped unnecessarily. (In a way, that wasn't so
bad: the skipped hint name would be the first hint character and the
extra last hint name would then be the same character doubled, so typing
the first character once would select it. But if the hint character was
also a valid Tridactyl binding, then the full two-character hint name
would also trigger that binding.)
There were also (infinitely) many cases where too few hint names would
be skipped, leading to prefixes among the hint names. For example, if
the hint characters were "abc" and there were 8 hints, the previous
method would skip only 2 hint names, leading to "c" and "ca" both being
generated as hint names.
The new method correctly skips 0 and 3 hint names in those cases.
This commit enables accessing content script values directly, like this:
(await tri.tabs[3].document.location.href)
tri.tabs[6].document.title = "New title!"
tri.tabs[9].tri.excmds.js("document.getElementById('blah').textContent").then(console.log)
Note that setting values, as shown in the above document.title example
above, cannot be synchronously, i.e. there is no way to wait for the
value to have been written is the content process before the background
process moves on to the next instruction. This is considered okay as
writing to the content process synchronously can be done with
(await tri.excmds.js("document.title = 'New title!'")) instead.
At the moment, accessing all tabs by not specifying an index in tri.tabs
is still not supported.
This commit implements a basic proxy enabling access to arbitrary
values/functions in tabs from the background script, like this:
tri.tabs[3].document.title.get().then(console.log)
tri.tabs[3].document.title.set("New title!").then(console.log)
tri.tabs[9].alert.apply("Hello world!")
tri.tabs[12].tri.excmds.js.apply("alert('Hello world!')")
Ease of implementation was chosen above ease of use. Enabling reading,
writing and calling directly through property accesses instead of
forcing the use of .get()/.set()/.apply() will be attempted in another
commit.