Closed marcustyphoon closed 6 days ago
Oh, fascinating: this isn't 100% reliable.
In Chrome, I am able to click the patio button, then resize the window horizontally during the soft navigate, and sometimes trigger a TypeError: Cannot read properties of null (reading 'before')
console error from line 171 here:
Weirdly, if I log the timeline element at this point, it:
editButton
is a reference tounbury_blog
script element, and said script element has no data-result or data-exception propertySo, a) the inject
code didn't remove the script element, so it probably didn't run, so the promise shouldn't have resolved, so why is this line of code running at all? And separately, b) why is that line of code failing if the entire post element is detached but seems fine?
Ah, I see. When the injected script element loads and executes, the post is still attached, but the button is not. When in doubt, log everything, I guess.
const cachedParents = [];
let element = editIcon;
while (element && element !== postElement) {
cachedParents.push(element);
element = element.parentElement;
}
const { trail = [], content = [] } = await timelineObject(postElement);
const items = trail.length + (content.length ? 1 : 0);
if (!editIcon.isConnected) {
console.log('---');
for (const element of cachedParents) {
console.log(
{
isConnected: element.isConnected,
'postElement.contains': postElement.contains(element)
},
element
);
}
console.log('---');
}
Description
One way to prevent the console being filled with errors whenever you scroll any timeline with the current MV3 branch, without needing to adjust every location we call
timelineObject()
, is to respond to injection requests for no-longer-attached-by-the-time-we-process elements with a promise that is neither resolved nor rejected. One would otherwise have to add a conditional early return to each invocation of the function.This diff is very nice, but it does leave around some mutation observers that will never get triggered. Probably fine?
Testing steps