Can injected scripts add rules to injected stylesheets?

In normal javascript, it seems like it's possible to select a particular stylesheet and add a rule to it via .addRule(...). Yet, it doesn't seem my injected script has access to my injected stylesheet because console.log(document.styleSheets) does not list my app-extension's injected stylesheet. Is there any way to access my injected stylesheet from my injected script so I can customize the styling of the elements I generate? There are, of course, cheesy workarounds. I could simply add the rules I want to a webpage's first stylesheet, but that lowers the seniority of the rule (in that adding !important tags won't guarantee it's implemented). The ultimage goal is to let user's customize the coloring of the pretty complicated & dynamic elements rendered by my injected script.


Thanks,


Pat

Replies

That is an interesting request - and something that currently isn't supported.


Can you please file a a bug using Apple's Feedback Assistant and reply with the ID once you've done that?


Also, if you could include some background on what your extension wants to do, that would be very helpful as well!

Thanks for your reply Mr. Weinstein! I watched your WWDC talk like 20 times while developing my app 😅. Here is the feature request ID: FB8853796. To expand further: My app extension, Keys, injects elements and would like users to be able to customize the color of these elements within the app (if they prefer the colors pink and purple say). Moreover, I would like to add a dark background behind the elements I inject so that they are easier to see for those with vision impairments. Several people in my App Store reviews have complained about these elements being difficult to see and about the necessity for a background to improve contrast, but I wouldn't want to do this for all users and would only do it if it were an option people could elect to toggle. If you want to see a video demonstration of Keys to see what I mean, there's one available on my YouTube channel "patrickshox".