Make sure that isTopLevelDoc uses the browser for the passed document, not the browser for the active tab.