Your code is incorrect, you can't access a cross-origin frame's contentWindow, so it throws an exception, but currently such errors aren't reported back to executeScript, which is why you get a `null`, see
https://crbug.com/1271527. The workaround for the lack of error reporting is to wrap the code in try/catch to handle any potential exceptions explicitly.
The solution to your original task is to run a new content script in the iframe, which you can do either declaratively (manifest.json or via registerContentScripts) or via executeScript with allFrames or frameIds parameter. This content script will run inside the iframe and be able to access its `document` and `window` directly.