question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

External Scripts, with and without document.write statements, and a Cancelled Callback

See original GitHub issue

Hi

Thanks for the awesome library, really useful.

I’m trying to use PostScribe to manage script injection with external scripts, some of which may have document.write calls in them, some of which may not. At the moment I’m sending all of them through Postscribe because even if there’s no document.write statement it’s very important to maintain the order of the external scripts.

The problem I’m having is that when I send an external script without a document.write statement in it to Postscribe, I get back a cancel object and then Postscribe ceases to function, as you might expect.

In order to work out whether there’s a document.write statement in the script, I would have to find some way of downloading and searching the cross-domain scripts with some sort of regex, I guess. It seems like you’re already doing something better.

What would be even better from my point of view would be a cancelled callback, which I can then work with and Postscribe would continue to perform its function for those external scripts that do have document write statements.

Tom

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tomgallaghercommented, May 13, 2017

Hi

OK so this was a timing issue. I was removing the first param targetnode from the page, after Postscribe checks for its presence but before the script was actually written to the page. So Postscribe just failed silently. Maybe another check for the target node before writing to the page? And maybe I should leave tidying up until I’ve actually got the whole thing working! Anyway, thanks for your time @jnewman

Tom

0reactions
jnewmancommented, May 12, 2017

I’ll add a check in a future release

Read more comments on GitHub >

github_iconTop Results From Across the Web

Execute write on doc: It isn't possible to write into a document ...
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...
Read more >
External JavaScript File - Javatpoint
We can create external JavaScript file and embed it in many html page. It provides code re usability because single JavaScript file can...
Read more >
JavaScript Tutorial: The Basics
Basic JavaScript Tutorial for the beginners.
Read more >
document.write() - Web APIs | MDN
Note: Using document.write() in deferred or asynchronous scripts will be ignored and you'll get a message like "A call to document.write() from ...
Read more >
Understand JavaScript Callback Functions and Use Them
Again, note the way we pass an anonymous function (a function without a name) to the forEach method as a parameter. So far...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found