Skip to content

Commit d606b95

Browse files
authored
Merge pull request #843 from gmetais/fix-object-errors
Fix object errors
2 parents 1a6fb85 + e720a39 commit d606b95

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ function phantomas(url, opts) {
8989

9090
// @see https://github.com/GoogleChrome/puppeteer/blob/v1.11.0/docs/api.md#pageevaluateonnewdocumentpagefunction-args
9191
injectJs: async (script) => {
92-
const debug = require("debug")("phantomas:injectJs"),
93-
preloadFile = require("fs").readFileSync(script, "utf8");
92+
const debug = require("debug")("phantomas:injectJs");
93+
94+
// Make sure we're on an HTML document, not an XML document for example
95+
const prefix = "if (document.constructor.name === 'HTMLDocument') {",
96+
suffix = "}";
97+
98+
const preloadFile =
99+
prefix + require("fs").readFileSync(script, "utf8") + suffix;
94100

95101
await page.evaluateOnNewDocument(preloadFile);
96102

test/integration-spec.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,11 @@
839839
- { url: "http://127.0.0.1:8888/browser-caching.html", type: "html", size: 517 }
840840
- { url: "http://127.0.0.1:8888/static/jquery-2.1.1.min.js", type: "js", size: 29734 }
841841

842+
# don't call MutationObserver on <object> tags
843+
- url: "/svg-as-object.html"
844+
metrics:
845+
jsErrors: 0
846+
842847
#
843848
# integration-test-extra section
844849
#

test/webroot/svg-as-object.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<body>
2+
<!--
3+
Objects should not throw the following JS errors:
4+
5+
TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'
6+
TypeError: Cannot read property 'scrollHeight' of null
7+
TypeError: Cannot read property 'getElementsByTagName' of null
8+
-->
9+
<object data="/static/example.svg" type="image/svg+xml"></object>
10+
</body>

0 commit comments

Comments
 (0)