krux / postscribe

Asynchronously write javascript, even with document.write.
MIT License
986 stars 156 forks source link

the ol' 'asynchronously-loaded' #381

Open joergipoergi opened 7 years ago

joergipoergi commented 7 years ago

Hi, maybe i'm getting something wrong, or one of my ad providers are.

but using postscribe with this string:

'<script type="text/javascript" src="//www.googletagservices.com/tag/js/gpt.js">
googletag.pubads().definePassback("/53015287/derstandard.at_d_de_300x250_1", [300, 250]).setClickUrl("%%CLICK_URL_UNESC%%").display();
</script>'

yields this error Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

of course i have to say, these guys are trying to implement some form of header-bidding, ie, they call a couple of programmatic-adproviders, let each of them do their own bidding and then choose the best bidder. It's all very complicated and i understand only half of it.

I don't think it's a bug and i actually want the providers (they are called yieldlove) to change their code, but maybe you guys have a better explanation?

I am a developer, so you can talk normal to me. I work for a big austrian newspaper.

jnewman commented 7 years ago

Try moving googletag.pubads().definePassback("/53015287/derstandard.at_d_de_300x250_1", [300, 250]).setClickUrl("%%CLICK_URL_UNESC%%").display(); into a separate script tag if possible.

oller commented 6 years ago

Did you get this working in the end @joergipoergi?

I'm hitting the same error when trying to execute the following code after page load.

var tag = `<ins class='dcmads' style='display:inline-block;width:320px;height:50px'
            data-dcm-placement='*id*'
            data-dcm-rendering-mode='iframe'
            data-dcm-https-only
            data-dcm-resettable-device-id=''
            data-dcm-app-id=''>
            <script src='https://www.googletagservices.com/dcm/dcmads.js'></script>
        </ins>`;

        postscribe(newElement, tag, {
            done: function () {
                console.info('ad should be loaded!');
            }
        });

Encountering the same warning thrown from dcmads.js, so it's loading fine then chrome is throwing the same warning as you were getting : Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

Any insight appreciated @jnewman . Cheers!

hirohanin commented 6 years ago

Hi any resolutions here

jnewman commented 6 years ago

@oller can you send me a test page? I'm not able to reproduce this error. A https://plnkr.co would be ideal.

hirohanin commented 6 years ago

this can be solved using google light passback tag instead of normal gpt tag