Fix race condition in content script