package
Disables or reassigns document.write to prevent a blank page.
npm install ember-disable-document-writeGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.
Have you ever had users of your Ember app complain about your site going completely blank for no apparent reason? You and your customers are probably experiencing an unwanted side effect from third party code trying to insert a script into your page using document.write().
Calling document.write() on a page with an Ember app has the unfortunate side effect of completely replacing the content of your page with whatever is passed as an argument, effectively blanking out your page. This is because document.write() will call document.open() on an already loaded document (see notes section here), which clears the contents that were written previously.
Most developers avoid using document.write for this exact reason, however in this age of third party ads and addons, you never know when someone's irresponsible use of document.write is going to bite you.
One common way to prevent third parties from using document.write is to reassign the function to a non-operation. That's the approach this addon takes, using a service and an instance initializer to replace the document.write function with whatever you'd like (or a noop by default).
This addon provides a document-service blueprint to generate a services/document.js to allow you to override the write function.
ember generate document-serviceThis will generate the following:
// app/services/document.js
import DocumentService from 'ember-disable-document-write/services/document';
export default DocumentService.extend({
/*
init() {
this._super(...arguments);
},
*/
write(/* content */) {
// insert any functionality to be executed when document.write is called
// you can log, report, or use a "safe" write option like `Node.insertBefore` or `document.appendChild`
}
});This README outlines the details of collaborating on this Ember addon.
git clone <repository-url> this repositorycd ember-disable-document-writenpm installbower installember servenpm test (Runs ember try:each && npm run nodetest to test your addon against multiple Ember versions)ember testember test --servernpm run nodetestember buildFor more information on using ember-cli, visit http://ember-cli.com/.
Estimated unpacked size across 66 packages.
3.4 MB+
Includes dependencies.