-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Specifying css
origin as USER
in declarative/registered content scripts
#414
Comments
Extensions styles are already user level in Safari. I am supportive of having a way to change between user and author. |
Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1679997 While there is consensus on the capability, I believe that we haven't talked about the exact shape of the API yet. The The Because this feature makes sense in manifest.json and scripting.registerContentScripts, just "origin" would be confusing, so I propose to stick with the Since the scripting namespace is already using the upper case variants of the value, I would continue that practice in the improved API. |
I plan to add support for |
WebKit issue tracking this: https://bugs.webkit.org/show_bug.cgi?id=273122 |
https://webkit.org/b/273122 rdar://problem/126916972 Reviewed by Antti Koivisto. Change web extension content styles to be author level instead of user level by default. To allow extensions to still use user level, added support for `cssOrigin` in the `tabs.insertCSS()` options, as well as `origin` in the `scripting.insertCSS` options. Accepted values are `user` and `author`. In addition, this introduces `cssOrigin` in `scripting.registerContentScripts()` and `css_origin` for the `content_scripts` entry in the manifest. These are new options and are being discussed in the WECG at w3c/webextensions#414. * Source/WebCore/en.lproj/Localizable.strings: Updated. * Source/WebKit/Shared/Extensions/WebExtensionDynamicScripts.serialization.in: * Source/WebKit/Shared/Extensions/WebExtensionRegisteredScriptParameters.h: * Source/WebKit/Shared/Extensions/WebExtensionScriptInjectionParameters.h: * Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPIScriptingCocoa.mm: (WebKit::WebExtensionContext::scriptingInsertCSS): (WebKit::WebExtensionContext::createInjectedContentForScripts): * Source/WebKit/UIProcess/Extensions/Cocoa/API/WebExtensionContextAPITabsCocoa.mm: (WebKit::WebExtensionContext::tabsInsertCSS): * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionCocoa.mm: (WebKit::WebExtension::populateContentScriptPropertiesIfNeeded): * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionContextCocoa.mm: (WebKit::WebExtensionContext::addInjectedContent): * Source/WebKit/UIProcess/Extensions/Cocoa/WebExtensionDynamicScriptsCocoa.mm: (WebKit::WebExtensionDynamicScripts::injectStyleSheets): * Source/WebKit/UIProcess/Extensions/WebExtension.h: * Source/WebKit/UIProcess/Extensions/WebExtensionDynamicScripts.h: * Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPIScriptingCocoa.mm: (WebKit::toWebAPI): Added origin. (WebKit::WebExtensionAPIScripting::executeScript): Return early if outExceptionString is set. (WebKit::WebExtensionAPIScripting::insertCSS): Ditto. (WebKit::WebExtensionAPIScripting::removeCSS): Ditto. (WebKit::WebExtensionAPIScripting::validateCSS): Added origin. (WebKit::WebExtensionAPIScripting::validateRegisteredScripts): Ditto. (WebKit::WebExtensionAPIScripting::parseCSSInjectionOptions): Ditto. * Source/WebKit/WebProcess/Extensions/API/Cocoa/WebExtensionAPITabsCocoa.mm: (WebKit::WebExtensionAPITabs::parseScriptOptions): * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtension.mm: (TestWebKitAPI::TEST(WKWebExtension, ContentScriptsParsing)): Added new cases. * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPIScripting.mm: (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, ErrorsCSS)): Added new error case. (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, ErrorsRegisteredContentScript)): Ditto. (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, CSSUserOrigin)): Added. (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, CSSAuthorOrigin)): Added. (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, World)): Fixed test that was always passing. (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, RegisterContentScriptsWithCSSUserOrigin)): Added. (TestWebKitAPI::TEST(WKWebExtensionAPIScripting, RegisterContentScriptsWithCSSAuthorOrigin)): Added. * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionAPITabs.mm: (TestWebKitAPI::TEST(WKWebExtensionAPITabs, Errors)): Added new error case. (TestWebKitAPI::TEST(WKWebExtensionAPITabs, CSSUserOrigin)): Added. (TestWebKitAPI::TEST(WKWebExtensionAPITabs, CSSAuthorOrigin)): Added. * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionContext.mm: (TestWebKitAPI::TEST(WKWebExtensionContext, ContentScriptsParsing)): Added new cases. * Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebExtensionController.mm: (TestWebKitAPI::TEST(WKWebExtensionController, CSSUserOrigin)): Added. (TestWebKitAPI::TEST(WKWebExtensionController, CSSAuthorOrigin)): Added. Canonical link: https://commits.webkit.org/278387@main
There should be a way to specify
origin: 'USER'
of CSS content scripts that are 1) declared in manifest.json, 2) registered via chrome.scripting.registerContentScripts.It would align the API with the existing
world
parameter forjs
content scripts.Why is it important? Because the
USER
origin is the only way to override!important
in inlinestyle
attributes of a web page. Currently we can only use chrome.scripting.insertCSS for that, but it's not declarative so it requires observing navigation, which is inefficient as it wakes up the service worker frequently, it may also easily cause a flash of unstyled content if the page loaded before the SW started and the browser processed the API call.The text was updated successfully, but these errors were encountered: