Closed Bug 1785303 Opened 3 years ago Closed 3 years ago

contentDocument and getSVGDocument() are always null for <object> embedding SVG

Categories

(Core :: SVG, defect)

Firefox 103
defect

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: r, Unassigned)

Details

Attachments

(3 files, 1 obsolete file)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:103.0) Gecko/20100101 Firefox/103.0

Steps to reproduce:

In an HTML file, embed an SVG in an <object> element, and add a script that accesses the <object> element's contentDocument or calls getSVGDocument() on it. Serve the HTML and SVG files from the same domain.

test.html:

<!doctype html>
<object type="image/svg+xml" width="100" height="100" data="test.svg"></object>
<script>
let obj = document.querySelector('object');
obj.addEventListener('load', function() {
console.log('contentDocument is', obj.contentDocument);
console.log('getSVGDocument returns', obj.getSVGDocument());
});
</script>

test.svg:

<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="red" />
</svg>

Actual results:

Both values are null.

Expected results:

Both values should be the SVG's content document.

This is the expected behaviour as documented here: https://developer.mozilla.org/en-US/docs/Web/SVG/Scripting and as observed in Chromium (93.0.4530.0) and Safari (12.1.2)

The values should be null on cross-origin access, but this shouldn't apply here as both files are served from the same domain.

The Bugbug bot thinks this bug should belong to the 'Core::SVG' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → SVG
Product: Firefox → Core
Attached file reporter's testcase (obsolete) —
Attachment #9290411 - Attachment is obsolete: true

Seems OK to me when I run your testcase. I'm using a Mac too.

Status: UNCONFIRMED → RESOLVED
Closed: 3 years ago
Resolution: --- → WORKSFORME

Just to make sure the setup is identical, I've uploaded the test case to a server: https://foon.uk/x/firefox-bug/test.html

I've put Firefox in "Troubleshooting Mode" which I understand disables all customizations, and I still get null.

Screenshot: https://i.imgur.com/DDycglC.png

Attached image Screenshot of the issue

That works for me too. Perhaps an extension you have is causing problems. Try safe mode.

The reporter said

I've put Firefox in "Troubleshooting Mode" which I understand disables all customizations, and I still get null.

(Troubleshooting Mode == safe mode)

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: