Skip to content

devtools: Implement Style Editor tab#44517

Merged
eerii merged 3 commits into
servo:mainfrom
rovertrack:stylesheet
Apr 29, 2026
Merged

devtools: Implement Style Editor tab#44517
eerii merged 3 commits into
servo:mainfrom
rovertrack:stylesheet

Conversation

@rovertrack

@rovertrack rovertrack commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

This PR focuses on forwarding the stylesheets and CSS text to the devtools.
watcher gets request for resource-available it registers in StyleSheetActor and gets the stylesheets.
StyleSheetActor asks the script_thread for stylesheets for the current document in the pipeline sends back to StyleSheetActor which is sent over for the response.
when the request comes for the CSS text which is a getText request it takes in resource id and the stylesheet index, for each stylesheets it check if it is inline it sends it unchanged, if its not inline it reconstruct it according to the CSSRules either of them are sent over the protocol to the devtools client and it shows up in the style editor.
Added tests for stylesheets resources and stylesheets CSS text content.

Testing: ./mach test-devtools test_stylesheet
Part of: #44315

@rovertrack

Copy link
Copy Markdown
Contributor Author

How it looks after the sheets are forwarded
Screenshot 2026-04-27 004940

Comment thread components/devtools/actors/stylesheets.rs

@eerii eerii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change! We are going to have to add tests for inline and not inline stylesheets.

I tested this (in https://servo.org) and inline style shows, but the other ones fail with NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]. The error shows in the Browser Console and as a banner in DevTools.

Comment thread components/devtools/actors/stylesheets.rs
Comment thread components/devtools/actors/stylesheets.rs Outdated
Comment thread components/devtools/actors/stylesheets.rs
Comment thread components/devtools/actors/stylesheets.rs Outdated
},
"getText" => {
let resource_id = msg.get("resourceId").and_then(|v| v.as_str()).unwrap_or("");
// Parse the index from the resourceId ("{browsing_context_id}-{index}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this format something that the Firefox client expects or something we are using internally?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[{"resourceId":"server1.conn0.watcher41.process7//windowGlobalTarget2:stylesheet:1",
"disabled":false,
"constructed":false,
"fileName":null,
"href":null,
"isNew":false,
"atRules":[],
"nodeHref":"http://localhost:8000/p.html",
"ruleCount":2,
"sourceMapBaseURL":"http://localhost:8000/p.html",
"sourceMapURL":"",
"styleSheetIndex":1,
"system":false,
"title":null}]]],\

This is how firefox to firefox stylesheet farwarding happens and each stylesheets resource id helps in getting their CSStext content in the getText message to identify a specific index
and instead of naming the resource like the above i thought of a more convenient one )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, great, thanks for looking into that! :)

Unrelated to this PR, but @atbrakhi, look at this. They are using the long form of the actor id here, it's more evidence that it's important and maybe that's why the workers are failing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very certain, we need to have it in order to properly support workers. This is another excellent hint indeed. I have added this in meta issue #44257

Comment thread components/devtools/actors/stylesheets.rs Outdated
Comment thread components/devtools/actors/stylesheets.rs Outdated
Signed-off-by: Rover track <rishan.pgowda@gmail.com>
@rovertrack rovertrack requested a review from eerii April 28, 2026 21:02
@rovertrack rovertrack marked this pull request as ready for review April 28, 2026 21:04
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 28, 2026
@rovertrack

Copy link
Copy Markdown
Contributor Author

but the other ones fail with NS_ERROR_FILE_UNRECOGNIZED_PATH: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsIFile.initWithPath]. The error shows in the Browser Console and as a banner in DevTools.

Now its showing the styles for external ones too!

@eerii eerii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more comments but it's looking good! I tried it again, and now external style sheets show, even if they say "Error fetching CSS text" on Servo's main page. But that's already a great improvement! I think we can leave it as is for this PR and add a TODO to tackle it in a followup, otherwise this will get too big.

Image Image

Comment thread components/devtools/actors/watcher.rs Outdated
Comment thread components/devtools/actors/stylesheets.rs Outdated
},
"getText" => {
let resource_id = msg.get("resourceId").and_then(|v| v.as_str()).unwrap_or("");
// Parse the index from the resourceId ("{browsing_context_id}-{index}")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, great, thanks for looking into that! :)

Unrelated to this PR, but @atbrakhi, look at this. They are using the long form of the actor id here, it's more evidence that it's important and maybe that's why the workers are failing

Comment thread components/devtools/actors/stylesheets.rs
@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Apr 29, 2026
@rovertrack

Copy link
Copy Markdown
Contributor Author

Some more comments but it's looking good! I tried it again, and now external style sheets show, even if they say "Error fetching CSS text" on Servo's main page. But that's already a great improvement! I think we can leave it as is for this PR and add a TODO to tackle it in a followup, otherwise this will get too big.

Image Image

it works when you test with your local html !!
This is being shown error in fetching because for some reason orign_clean is false

fn GetCssRules(&self, cx: &mut JSContext) -> Fallible<DomRoot<CSSRuleList>> {
if !self.origin_clean.get() {
return Err(Error::Security(None));
}
Ok(self.rulelist(cx))
}

Signed-off-by: Rover track <rishan.pgowda@gmail.com>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 29, 2026
@rovertrack

Copy link
Copy Markdown
Contributor Author

Some more comments but it's looking good! I tried it again, and now external style sheets show, even if they say "Error fetching CSS text" on Servo's main page. But that's already a great improvement! I think we can leave it as is for this PR and add a TODO to tackle it in a followup, otherwise this will get too big.
Image Image

it works when you test with your local html !! This is being shown error in fetching because for some reason orign_clean is false

fn GetCssRules(&self, cx: &mut JSContext) -> Fallible<DomRoot<CSSRuleList>> {
if !self.origin_clean.get() {
return Err(Error::Security(None));
}
Ok(self.rulelist(cx))
}

resolved :)

Screenshot 2026-04-29 220750

The matching of CSS text formatting as that of raw source can be a later improvement.
added TODO

@eerii eerii changed the title Devtools: Forward style sheets to devtools devtools: Implement Style Editor tab Apr 29, 2026

@eerii eerii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Just a small lint fix and this is ready for landing.

It works great on https://servo.org and some local tests. I did some testing in larger sites like https://m.huaweimossel.com and it seems like we ran into issues with really big CSS files. But I think it's something we can investigate after this initial implementation is merged.

Followups:

  • Show source location for style rules, linking to the file in the Style Editor
  • Look into issues displaying big CSS files.
  • Proper formatting for external CSS files.

};
request.reply_final(&msg)?
},
/// TODO: Fix CSS text formatting of external sheets, match same as source.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be //, not ///. The latter is a documentation comment reserved for functions and structs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry
Thanks

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Apr 29, 2026
Signed-off-by: rovertrack <160643895+rovertrack@users.noreply.github.com>
@servo-highfive servo-highfive added the S-awaiting-review There is new code that needs to be reviewed. label Apr 29, 2026
@rovertrack rovertrack requested a review from eerii April 29, 2026 18:52

@eerii eerii left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you for tackling this! :)

@servo-highfive servo-highfive removed the S-awaiting-review There is new code that needs to be reviewed. label Apr 29, 2026
@eerii eerii added this pull request to the merge queue Apr 29, 2026
@servo-highfive servo-highfive added the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 29, 2026
Merged via the queue into servo:main with commit 569583a Apr 29, 2026
33 checks passed
@servo-highfive servo-highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Apr 29, 2026
@atbrakhi atbrakhi mentioned this pull request May 5, 2026
5 tasks
@eerii eerii mentioned this pull request May 6, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants