gitlabEdit

prevent-element-src-loading

Prevents targeted elements (script, img, iframe, link) from loading specific resources by intercepting src/href assignments and redirecting them to local mock data. It also neutralizes onerror handlers and error event listeners to ensure the loading fails silently without triggering errors/walls.

Parameters

Name
Description
Mandatory
Default value

tagName

The type of HTML element to target. Accepted values: script, img, iframe, link

Yes

n.a.

search

The string or regex used to match the URL in the src (for scripts/imgs/iframes) or href (for links). If the string begins and ends with a slash ( / ), it is treated as a regular expression.

Yes

n.a.

Use cases

  1. Neutralizing circumvention providers that use onerror attributes to detect blocked scripts/iframes.

  2. Preventing the loading of tracking pixels or scripts while keeping the DOM structure intact to avoid layout breakage.

  3. Silently blocking resource loads that would otherwise trigger walls and errors.

Filter examples

The following table lists examples that use the prevent-element-src-loading snippet:

Filter
Result

prevent-element-src-loading 'script' /sdk/

Replaces the src of any script containing "sdk" with a Base64 encoded empty function. The script will not load and onerror will not fire.

prevent-element-src-loading 'img' /banner_\d+/

Matches images like banner_468.png and replaces them with a transparent 1x1 GIF.

prevent-element-src-loading 'iframe' 'message-alert'

Prevents iframes with src matching message-alert from loading, replacing the src with an empty data-URI div.

Debugging

The following table contains messages you'll find useful during debugging:

#
Message
When
Meaning

1

Wrapped setAttribute function

After the snippet hooks HTML[Element]Element.prototype.setAttribute.

setAttribute calls for this tag type are now intercepted.

2

Wrapped src/href property setter

After hooking the direct .src or .href property on the element prototype.

Direct assignments (e.g., img.src = ...) are now intercepted.

3

Wrapped onerror property setter

During the first call of the snippet.

Any attempt by the site to set an onerror callback on matched elements is intercepted.

4

Wrapped addEventListener

During the first call of the snippet.

Attempts to add error event listeners via addEventListener are now intercepted.

5

Replaced ... setter <<url>> → data:...

When a URL matches the search parameter.

The resource load was successfully redirected to mock data.

6

Replaced error event handler on [element] with () => {}

When the site tries to listen for an error on a blocked element.

The error listener was neutralized to prevent detection.

Last updated