Fork Sync: Update from parent repository#307
Fork Sync: Update from parent repository#307github-actions[bot] wants to merge 27 commits intomasterfrom
Conversation
New directive: `join:[separator][sub-directives]` [separator] is an author-defined two-character string to be used to split the following sub-directives string. The sub-directives are fed back into the helper scriptlet to generate sub-content, which will be joined into a single string. Example: ...##+js(trusted-prevent-fetch, propstomatch, join:--length:10-20--[some literal content]--length:80-100-- push['ads'])
Related issue: uBlockOrigin/uBlock-issues#3934
Revert gorhill@7aff7da77d for Safari.
…on"" This reverts commit c7ff0f8.
Related discussion: uBlockOrigin/uAssets#30731
Related issue: uBlockOrigin/uAssets#30636
Possibly will fix cases of no content scripts found in Safari. Related issue: uBlockOrigin/uAssets#30158 (comment)
|
[puLL-Merge] - brave/uBlock@307 Diffdiff --git src/js/resources/create-html.js src/js/resources/create-html.js
index 9b22976d113b1..1329b3da06207 100644
--- src/js/resources/create-html.js
+++ src/js/resources/create-html.js
@@ -71,15 +71,12 @@ function trustedCreateHTML(
const duration = parseInt(durationStr, 10);
const domParser = new DOMParser();
const externalDoc = domParser.parseFromString(htmlStr, 'text/html');
- const docFragment = new DocumentFragment();
- const toRemove = [];
+ const toAppend = [];
while ( externalDoc.body.firstChild !== null ) {
- const imported = document.adoptNode(externalDoc.body.firstChild);
- docFragment.appendChild(imported);
- if ( isNaN(duration) ) { continue; }
- toRemove.push(imported);
+ toAppend.push(document.adoptNode(externalDoc.body.firstChild));
}
- if ( docFragment.firstChild === null ) { return; }
+ if ( toAppend.length === 0 ) { return; }
+ const toRemove = [];
const remove = ( ) => {
for ( const node of toRemove ) {
if ( node.parentNode === null ) { continue; }
@@ -87,10 +84,21 @@ function trustedCreateHTML(
}
safe.uboLog(logPrefix, 'Node(s) removed');
};
+ const appendOne = (target, nodes) => {
+ for ( const node of nodes ) {
+ target.append(node);
+ if ( isNaN(duration) ) { continue; }
+ toRemove.push(node);
+ }
+ };
const append = ( ) => {
- const parent = document.querySelector(parentSelector);
- if ( parent === null ) { return false; }
- parent.append(docFragment);
+ const targets = document.querySelectorAll(parentSelector);
+ if ( targets.length === 0 ) { return false; }
+ const limit = Math.min(targets.length, extraArgs.limit || 1) - 1;
+ for ( let i = 0; i < limit; i++ ) {
+ appendOne(targets[i], toAppend.map(a => a.cloneNode(true)));
+ }
+ appendOne(targets[limit], toAppend);
safe.uboLog(logPrefix, 'Node(s) appended');
if ( toRemove.length === 0 ) { return true; }
setTimeout(remove, duration);
diff --git src/js/resources/prevent-fetch.js src/js/resources/prevent-fetch.js
index 7a161ecc0a703..dbe096a5dbc7c 100644
--- src/js/resources/prevent-fetch.js
+++ src/js/resources/prevent-fetch.js
@@ -51,6 +51,7 @@ function preventFetchFn(
const propNeedles = parsePropertiesToMatchFn(propsToMatch, 'url');
const validResponseProps = {
ok: [ false, true ],
+ status: [ 403 ],
statusText: [ '', 'Not Found' ],
type: [ 'basic', 'cors', 'default', 'error', 'opaque' ],
};
diff --git src/js/resources/scriptlets.js src/js/resources/scriptlets.js
index 687aa69c1785c..9c888b3d7ca2e 100755
--- src/js/resources/scriptlets.js
+++ src/js/resources/scriptlets.js
@@ -1828,7 +1828,7 @@ function trustedClickElement(
const pos2 = s2.indexOf('=');
const key = pos2 !== -1 ? s2.slice(0, pos2).trim() : s2;
const value = pos2 !== -1 ? s2.slice(pos2+1).trim() : '';
- out.re = new RegExp(`^${this.escapeRegexChars(key)}=${this.escapeRegexChars(value)}`);
+ out.re = new RegExp(`^${safe.escapeRegexChars(key)}=${safe.escapeRegexChars(value)}`);
return out;
}).filter(details => details !== undefined);
const allCookies = assertions.some(o => o.type === 'cookie')
diff --git src/js/resources/utils.js src/js/resources/utils.js
index 45c96ca32522a..52e7a9b450b24 100644
--- src/js/resources/utils.js
+++ src/js/resources/utils.js
@@ -220,6 +220,14 @@ export function generateContentFn(trusted, directive) {
warXHR.send();
}).catch(( ) => '');
}
+ if ( directive.startsWith('join:') ) {
+ const parts = directive.slice(7)
+ .split(directive.slice(5, 7))
+ .map(a => generateContentFn(trusted, a));
+ return parts.some(a => a instanceof Promise)
+ ? Promise.all(parts).then(parts => parts.join(''))
+ : parts.join('');
+ }
if ( trusted ) {
return directive;
}
DescriptionThis PR makes several changes to uBlock's scriptlet resources:
Possible Issues
Security Hotspots
ChangesChanges
sequenceDiagram
participant Page as Web Page
participant Script as Scriptlet Engine
participant DOM as Document DOM
Note over Script: trustedCreateHTML flow
</details>
<!-- Generated by claude-opus-4-6 -->
|
This PR was automatically created by a GitHub Action triggered by a cron schedule. Please review the changes and merge if appropriate.