ulixee / unblocked

A suite of tools for protecting the web's open knowledge.
MIT License
130 stars 12 forks source link

FramesManager addPageCallback doesn't handle undefined frame #86

Closed soundofspace closed 3 months ago

soundofspace commented 6 months ago

FramesManager addPageCallback doesn't handle an undefined frame returned by getFrameForExecutionContext.

Not entirely sure if it should ever get here if frame is undefined or it is the symptom of a larger problem. Current problem right now is that addPageCallback will call the onCallback function with frame undefined resulting in :

UnhandledRejection; TypeError: Cannot read properties of undefined (reading 'frameId')
agent/main/lib/InjectedScripts.ts:46:48

What worries me a bit more, but might just be my personal ide setup is that TS thinks is can't be undefined, hence not giving compile time errors (which is probably how this got under the radar).

image image

But looking at the function is can definitely return undefined

image
blakebyrnes commented 6 months ago

I'm thinking we should probably just not call the callback if there's no frame. It seems like it's just too confusing to try to handle a if a frame is already detached.

const frame = this.getFrameForExecutionContext(event.executionContextId);
if (frame) onCallback(event.payload, frame);