Fix window.open return undefined

Fix this problem when content scripts do not have any access to a page's global window object.
It would be good to explain in comments why do use this hacks here.