I would guess that the problem is that the title is actually defined within the page HTML. Since this is a beforeNavigate
event, the page hasn't been loaded yet so in general the title isn't available yet, just the URL.
One solution might be to use the navigate
event instead of beforeNavigate
, provided you don't specifically need to do anything before the page actually loads. However I'm not sure that actually guarantees the page will be loaded, but it does make it more likely.
If it's still a problem, a more complicated alternative is to use an injected script that sends a message to the global page whenever a page loads. Use the DOM ready event in the injected script, then just dispatch a message to the global page containing the page title. Use if (window == window.top)
to prevent embedded iframes from also sending a message.