Skip to content

Implement CSSStyleSheet ownerNode and href #992

@philipwalton

Description

@philipwalton

I know this project has a disclaimer about not supporting all of the CSSOM, but I encountered some errors while trying to get HTML Inspector to work with jsdom instead of PhatomJS, and I tracked it down to the lack of these two properties on the CSSStyleSheet object.

From what I can tell, the following function in level2/style.js is where this could/should be added, but I'm not familiar enough with the codebase to know for sure.

function evaluateStylesheet(data, sheet, baseUrl) {
  // this is the element
  var newStyleSheet = cssom.parse(data);
  var spliceArgs = newStyleSheet.cssRules;
  spliceArgs.unshift(0, sheet.cssRules.length);
  Array.prototype.splice.apply(sheet.cssRules, spliceArgs);
  scanForImportRules.call(this, sheet.cssRules, baseUrl);

  // Add references to `this` and `baseUrl`.
  sheet.href = baseUrl;
  sheet.ownerNode = this;

  this.ownerDocument.styleSheets.push(sheet);
}

Anyway, this changed work for me locally, so hopefully it's as simple as that. Thanks for the consideration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions