Bug 79653

Summary: Remove getMatchedCSSRules
Product: WebKit Reporter: Antti Koivisto <koivisto>
Component: CSSAssignee: Chris Dumez <cdumez>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, ap, cred+bugzilla, darin, emilio, itbeenews, jmayhew, joethomas, koivisto, kriomant, mitz, moz, oliver, pfeldman, sam, shezbaig.wk, syoichi, tkaraszewski
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=89240
Bug Depends on:    
Bug Blocks: 83298    
Attachments:
Description Flags
chrome os
none
Patch
none
Patch ews-feeder: commit-queue-

Description Antti Koivisto 2012-02-27 02:32:31 PST
Based on comments in bug 35015, getMatchedCSSRules was implemented purely to support inspector but is no longer used by it. Supporting the feature is complicating CSSStyleSelector and will be even more problematic with the planned stylesheet refactoring. It should be removed.
Comment 1 Adam Barth 2012-02-27 11:02:41 PST
How often is this feature used by web sites?
Comment 2 Antti Koivisto 2012-02-27 11:29:47 PST
I can't imagine it having any real use cases in the web. It is an introspection API (a poor one, due to security constraints).
Comment 4 jmayhew 2012-05-14 13:51:57 PDT
We are using this API specifically so we can introspect CSS on DOM objects. Currently getMatchedCSSRules it is still unable to get rules for pseudo classes but we are working to have the spec updated to include this functionality. 

We would be able to get the functionality we want if the APIs that the web inspector uses were available to all web apps, but it appears that they are limited to use within the inspector windows. As a result our only option is to use getMatchedCSSRules. 

If this API is dropped we would need an API to take its place. Perhaps, the APIs the inspector uses could be opened up, or some chrome extension permissions could be added that open up use of those APIs to extensions.
Comment 5 Tyler Karaszewski 2012-06-07 11:59:42 PDT
We use this at Evernote in a very similar way to how it's mentioned in comment #4. We have an extension that uses it to do introspection on a page and retrieve that original style rules that apply to each element on that page.
Comment 6 Joe Nelson 2013-02-13 19:30:24 PST
If you remove this function please provide access to whatever API that the inspector uses.

Style introspection is very useful. I use it in my CSS refactoring tool:
https://github.com/begriffs/css-ratiocinator
Comment 7 Pavel Feldman 2013-02-13 22:37:33 PST
It is a part of remote debugging protocol. We will make it public / documented some time soon, but it is already available.
Comment 8 kriomant 2013-09-24 20:31:16 PDT
I use getMatchedCSSRules in my Chrome extension. Extension uses devtool panel, so using remote debugging protocol is not an option - as far as I know opening devtools will prevent extensions from using it.

So it will be good to have some method for extensions to introspect page styles. It would be even better if this method doesn't suffer from same-origin restriction. Currently I have to load and embed all stylesheets to work around it.
Comment 9 Oliver Hunt 2013-09-24 23:03:53 PDT
(In reply to comment #8)
> I use getMatchedCSSRules in my Chrome extension. Extension uses devtool panel, so using remote debugging protocol is not an option - as far as I know opening devtools will prevent extensions from using it.
> 
> So it will be good to have some method for extensions to introspect page styles. It would be even better if this method doesn't suffer from same-origin restriction. Currently I have to load and embed all stylesheets to work around it.

Chrome forked from webkit, so you are better off posting in their bug db
Comment 10 Antti Koivisto 2014-03-18 09:09:49 PDT
<rdar://problem/16354443>
Comment 11 j.j. 2017-08-24 05:41:21 PDT
Chrome Intent to Remove: getMatchedCSSRules()
https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/-_Al0I5Rm9Q
Comment 12 Azrael 2017-11-12 13:33:12 PST
Created attachment 326725 [details]
chrome os
Comment 13 Alexey Proskuryakov 2017-11-17 09:51:21 PST
The content of attachment 326725 [details] has been deleted for the following reason:

Irrelevant attachment, likely spam or phishing.
Comment 14 Sam Weinig 2021-02-20 12:13:32 PST
Chrome and Firefox have both removed this. We should try to as well.
Comment 15 Sam Weinig 2021-02-20 12:27:06 PST
Created attachment 421100 [details]
Patch
Comment 16 Sam Weinig 2021-02-20 12:30:26 PST
(In reply to Sam Weinig from comment #15)
> Created attachment 421100 [details]
> Patch

Removing this is going to be harder than I would have hoped. A few problems:

- Safari seems to be using it, we need to find out why and get them off of it.
- It seems we made getMatchedCSSRules public API in WebKitLegacy. While it is deprecated, it's not obsolete, so we likely need to keep it working there at least. I am curious if we can make an implementation that is less invaisive just for the Webkit Legacy case, but I am not super optimistic about it.
Comment 17 Sam Weinig 2021-02-20 12:32:06 PST
Created attachment 421101 [details]
Patch
Comment 18 Chris Dumez 2022-07-15 16:45:26 PDT
Pull request: https://github.com/WebKit/WebKit/pull/2479
Comment 19 EWS 2022-07-16 14:49:58 PDT
Committed 252542@main (7d88064a3d12): <https://commits.webkit.org/252542@main>

Reviewed commits have been landed. Closing PR #2479 and removing active labels.