Closed Bug 1880718 Opened 2 years ago Closed 1 year ago

Constructed stylesheet background-image with relative URL is not applied when rule is inserted with Stylesheet#insertRule

Categories

(Core :: DOM: CSS Object Model, defect)

Firefox 122
defect

Tracking

()

RESOLVED FIXED
125 Branch
Tracking Status
firefox125 --- fixed

People

(Reporter: josh, Assigned: emilio)

References

Details

Attachments

(5 files)

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0

Steps to reproduce:

  1. In a new folder, copy the following HTML code into example.html:
<!DOCTYPE html>
<html lang="en">
<body>
  <script>
    const css = new CSSStyleSheet()
    document.adoptedStyleSheets.push(css)

    css.insertRule(`
      body {
        background-image: url("image.svg");
        min-height: 100vh;
      }
    `)
  </script>
</body>
</html>
  1. Download an SVG file and save it as image.svg.

  2. Run a web server on port 8000 serving the contents of the folder.

  3. In Firefox, browse to http://localhost:8000/example.html.

Actual results:

The document body did not show the background image. When I inspected the element with the developer console, the following console message appeared: Security Error: Content at http://127.0.0.1:8000/index.html may not load or link to chrome://devtools/content/inspector/image.svg.

Expected results:

The document body should have shown image.svg as its background, in exactly the same way as if background-image: url("image.svg"); was entered directly in CSS.

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

Component: Untriaged → General
Product: Firefox → DevTools

I think the bot is wrong. This doesn't seem to me to be a problem with devtools, it seems to be a problem with how dynamic CSS is treated by the renderer.

Product: DevTools → Firefox

I can reproduce the issue, and it looks like this might be caused by insertRule ?
If I'm using replaceSync to populate the stylesheet instead, I do get the background image

      const css = new CSSStyleSheet();
      css.replaceSync(`
        body {
          background-image: url("image.svg");
          min-height: 100vh;
        }
      `);
      document.adoptedStyleSheets.push(css);

Note that the computed value of background-image is url("about:invalid")

Component: General → DOM: CSS Object Model
Product: Firefox → Core
Status: UNCONFIRMED → NEW
Ever confirmed: true
Summary: When a dynamic stylesheet refers to a relative url, Firefox will treat it as relative to chrome://devtools → Constructed stylesheet background-image with relative URL is not applied when rule is inserted with Stylesheet#insertRule

The severity field is not set for this bug.
:jfkthame, could you have a look please?

For more information, please visit BugBot documentation.

Flags: needinfo?(jfkthame)
Attachment #9391126 - Attachment description: testcase 1 (from reporter's html in initial comment) → reference case 1 (using full/absolute URL)
Severity: -- → S3

I can reproduce this in Nightly for as long as constructable stylesheets has been on by default via bug 1644102 (i.e. Nightly 2022-04-28 renders the reference cases as lime but the testcase as blank).

So: not a regression, but apparently a bug in our constructable stylesheets that's been present since it shipped.

emilio, maybe you can take a look & see if there's an easy fix to suggest here?

Blocks: 1520690
Flags: needinfo?(jfkthame) → needinfo?(emilio)

ReplaceSync did this, but if you don't call Replace() / ReplaceSync()
after construction we end up with the Servo_StyleSheet_Empty which has a
dummy URL data.

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Flags: needinfo?(emilio)
Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/2236c50908d6 Make sure that constructable stylesheets has the right url data after construction. r=dshin
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/45130 for changes under testing/web-platform/tests
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 125 Branch
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: