I know that this is simulating a native app but I think it makes more sense to sandbox the ad for testing.
Since the ad/window are on the same domain you might run into issues. I might assume some javascript works since it works here (and has access to the main window) but when deployed the script doesn't behave the same.