New rpnt (prev. sed) scriptlet · uBlockOrigin/uAssets · Discussion #18185 (original) (raw)
I saw a new commit here gorhill/uBlock@4187633 so i tested the new scriptlet.
But it doesn’t work always on my end. When i add example.com##+js(sed, #text, Domain) as a exampe it works when i open the page for the first time but after a reload the scriptlet doesn’t kick in.
Do i did a mistake? Or is this a bug? Tested with Firefox and uBlock Origin 1.49.3b17
You must be logged in to vote
You must be logged in to vote
16 replies
the scriptlet ends up processing itself...
Because on chromium it's inserted as an inline-script rather than a blob url ?
wondering though if it could be because
blob:is used to inject scriptlet in Firefox
The new sed.js scriptlet does not have to execute in the main (page) world, since it only deals with DOM nodes (there is no need to trap properties) and as such it can be executed in the isolated (extension's content script) world. This requires lot of changes to support the ability to execute a scriptlet in either world, and now I have the sed.js scriptlet injected as a content script rather than a page script, and as a result, Firefox's behavior now seems as good as Chromium. This also simplify a bit things since now the scriptlet does not have to worry about processing itself -- however we need to find out if it can end up processing uBO's scriptlets injected in main world, though I expect not.
I had to adjust the scriptlet a bit since it turns out that in Firefox it is injected earlier than Chromium: with Chromium, there is an html element in the DOM at injection time. No so with Firefox, there is nothing in the DOM, so the scriptlet has to be ready for this. So this tells content scripts are also injected reliably in Firefox, the issue is the blob:-based injection, it causes the scriptlets in main world to be executed much later. However without blob: we have potential security violations in Firefox because of page's CSP.
Should we ask Rob Wu on slack about Firefox' policy? Better than guessing I think.
Let's not raise the issue, if AdGuard's replace is fine, uBO's sed should be fine.
@stephenhawk8054 ghacks filter no longer works because admin added space before and after the word, so change the filter to ghacks.net##+js(rmnt, #text, /Advertisement/)
Is replacement limited to being a string or can it be a regex (which doesn't seem to work in my testing on Firefox)?
If it is a string, how could a comma , be included in the replacement text since it is also used as a delimiter?
You must be logged in to vote
1 reply
use \,
example:example.com##+js(sed, #text, Domain, Hello\,You)
I can confirm it works fine on Firefox now on all 3 tested domains. Also the filter i added for the video ads now working fine on Firefox. Thanks.
You must be logged in to vote
27 replies
Nope it doesn't..for context it was dropgalaxy 15 sec timer which doesn't get counted if browser is minimized anyway thanks for the help🥺
@BlazeFTL example.com##+js(trusted-set, document.visibilityState, visible)
@gorhill What does sed stand for? Asking for the wiki.
You must be logged in to vote
2 replies
sed is a find & replace linux command
(sed from stream editor)
I am probably abusing the original command name. I will move sed as an alias and provide a more meaningful default name, probably replace-node-text (which nobody will use).
uBlockOrigin/uBlock-issues#2531 (comment)
Can this be fixed using sed?
On https://www.mozilla.org/ja/firefox/browsers/mobile/android/, the download link has href="https://app.adjust.com/[...]?redirect=https://play.google.com/[...]
Can the scriptlet remove https://app.adjust.com/[...]?redirect= from href?
You must be logged in to vote
2 replies
Unlikely since the URL is uriComponentEncode-ed.
I would debug why on a Japanese PC/macbook/iMac the a href-sanitizer doesn't work for him (It works fine for me on a "Polish PC" in Firefox and Chrome).
And rather weak is his explanation that he needs a scriptlet already in uBo stable.
Asking for the wiki.
By the way in last dev build, I rename the scriptlet replace-node-text.js (that's essentially what it does), with alias rnt.js. sed.js still exist just for the sake of the filters already created, should wait for dev build rc4 to be available on Chromium before changing the existing filters.
You must be logged in to vote
0 replies
You must be logged in to vote
1 reply
So now you have to wait for 1.49.3rc5 or stable 1.49.4+.
The worst thing is that someone already wanted to do a similar operation with a paragraph in "article" and now I can't find it that discussion, as if he got a shadowban from Microsoft (found and Gorhill also pasted PoC filters to rewrite if someone can't start form 0 aftrr read commits documentation).
I tried to remove スポンサードリンク texts visible on https://rank1-media.com/I0000314 but rank1-media.com##+js(rpnt, .contents_m, スポンサードリンク) doesn't work. What did I wrong?
You must be logged in to vote
3 replies
Valid node names are what is listed at https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeName. A class name is not a node name. The rpnt/rmnt scriptlets should not be confused with the currently non-existing procedural cosmetic filter :remove-text() -- it works completely differently. Its primary purpose is to disable whole or part of inline javascript, I added the ability to select the target node type because why not, but the primary purpose is not cosmetic. What you have in mind is a procedural cosmetic operator such as :remove-text() which would be chained to CSS selectors or other cosmetic procedural operators.
The name of the node containing the target text is Errr see me too I got confused... maybe try:article, and since the target text in present in view-source:,
rank1-media.com##+js(rmnt, #text, スポンサードリンク)
Yes, working! Didn't know #text can be used here.
condition, pattern:
A string or regex which must be found in the text content of the node
in order for the substitution to occur.
example.com
example.com##+js(rpnt, #text, Example Domain, Changed)
=>
The text of <title> (page title) and <h1> changes.
example.com##+js(rpnt, #text, Example Domain, Changed, condition, Example)
=>
Only the text of <title> (page title) changes.
You must be logged in to vote
2 replies
But these two both work:example.com##+js(rmnt, #text, Example)
andexample.com##+js(rmnt, #text, Example, condition, Exa)
And this one doesn't work (correctly):example.com##+js(rmnt, #text, Example, condition, Exa3434)
Also these malform DOM tree:
example.com##+js(rpnt, , Example Domain, Changed) example.com##+js(rpnt,, Example Domain, Changed)
It may have already asked, but will it be possible to replace only part of target text?
Current behavior: remove entire text of target node and then insert replacement text
I want: remove only part of text in the target node specified by the first needle (regex) while the rest of the text unchanged. This means rpnt can be used as a lighter $replace for documents. It will also be convenient if the needle can be saved into $1 like this filter: ||imgur.com/*-assets/js/main.*.js$replace=/("hasSeenUploadRewardVideo"\,)!1/\$1true/
You must be logged in to vote
5 replies
Doesn't this work?
...##+js(rpnt, script, /("hasSeenUploadRewardVideo"\,)!1/, $1!0)
Ah, so saving string is already supported, that's good. But the main point is to replace only part of the text.
But the main point is to replace only part of the text
Sorry I don't understand what you are saying. rpnt plainly use String.prototype.replace internally, which allows for what you are asking. Try in console:
var a = 'blah blah "hasSeenUploadRewardVideo",!1 blah blah';
var b = a.replace(/("hasSeenUploadRewardVideo",)!1/, '$1!0')
b will then be blah blah "hasSeenUploadRewardVideo",!0 blah blah. Isn't this what you want?
Sorry, it was just my regex was wrong. I didn't escape ,, which apparently led to an unintended filter.
You can also use quotes if you don't want to mind commas:
...##+js(rpnt, script, '/("hasSeenUploadRewardVideo",)!1/', '$1!0')
You must be logged in to vote
2 replies
It's possible, but modifying HTML by RegEx is prone to errors, that's why in uBO source text is parsed by DOMParser to DOM tree and standard tools then can be used to filter elements.
I see. Thanks for the information.
Based on this: #18185 (reply in thread) , I think replace text using filterResponseData would be more reliable than rpnt scriptlet?