ulixee / unblocked

A suite of tools for protecting the web's open knowledge.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FramesManager addPageCallback doesn't handle undefined frame

soundofspace opened this issue · comments

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

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);