Skip to content

[in progress] scriptlets as an npm module #1757

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ test-results
.netlify
# VS Code user config
.vscode

# Auto-generated scriptlets file (built from @adguard/scriptlets)
injected/src/features/scriptlets-minimal.js
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "injected/src/features/Scriptlets"]
path = injected/src/features/Scriptlets
url = https://github.com/AdguardTeam/Scriptlets.git
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ docs/**/*
injected/src/types
special-pages/pages/**/types
injected/integration-test/extension/contentScope.js
injected/src/features/Scriptlets
**/*.json
**/*.md
**/*.html
Expand Down
2 changes: 1 addition & 1 deletion .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": ["stylelint-config-standard"],
"plugins": ["stylelint-csstree-validator"],
"ignoreFiles": ["build/**/*.css", "Sources/**/*.css", "docs/**/*.css", "special-pages/pages/**/*/dist/*.css", "injected/src/features/Scriptlets/**/*"],
"ignoreFiles": ["build/**/*.css", "Sources/**/*.css", "docs/**/*.css", "special-pages/pages/**/*/dist/*.css"],
"rules": {
"csstree/validator": {
"ignoreProperties": ["text-wrap", "view-transition-name"]
Expand Down
3 changes: 0 additions & 3 deletions build-output.eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// https://github.com/eslint/eslint/discussions/18806#discussioncomment-10848750

export default [
{
ignores: ['injected/src/features/Scriptlets', 'injected/src/features/scriptlets.js'],
},
{
languageOptions: {
ecmaVersion: 'latest',
Expand Down
3 changes: 1 addition & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export default tseslint.config(
'playwright-report',
'test-results',
'injected/src/types',
'injected/src/features/Scriptlets',
'injected/src/features/scriptlets.js',
'injected/src/features/scriptlets-minimal.js',
'.idea',
],
},
Expand Down
1 change: 1 addition & 0 deletions injected/entry-points/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function generateConfig() {
'apiManipulation',
'duckPlayer',
'duckPlayerNative',
'scriptlets',
],
},
};
Expand Down
118 changes: 118 additions & 0 deletions injected/integration-test/pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,122 @@ test.describe('Test integration pages', () => {
`./integration-test/test-pages/webcompat/config/modify-cookies.json`,
);
});

// Scriptlet integration page tests
test('Set Cookie Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/set-cookie.html',
'./integration-test/test-pages/scriptlets/config/set-cookie.json',
);
});

test('Set Local Storage Item Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/set-local-storage-item.html',
'./integration-test/test-pages/scriptlets/config/set-local-storage-item.json',
);
});

test('Set Constant Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/set-constant.html',
'./integration-test/test-pages/scriptlets/config/set-constant.json',
);
});

test('Trusted Set Cookie Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/trusted-set-cookie.html',
'./integration-test/test-pages/scriptlets/config/trusted-set-cookie.json',
);
});

test('Remove Cookie Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/remove-cookie.html',
'./integration-test/test-pages/scriptlets/config/remove-cookie.json',
);
});

test('Abort on Property Read Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/abort-on-property-read.html',
'./integration-test/test-pages/scriptlets/config/abort-on-property-read.json',
);
});

test('Abort on Property Write Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/abort-on-property-write.html',
'./integration-test/test-pages/scriptlets/config/abort-on-property-write.json',
);
});

test('Prevent Add Event Listener Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/prevent-addEventListener.html',
'./integration-test/test-pages/scriptlets/config/prevent-addEventListener.json',
);
});

test('Prevent Set Timeout Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/prevent-setTimeout.html',
'./integration-test/test-pages/scriptlets/config/prevent-setTimeout.json',
);
});

test('Prevent Window Open Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/prevent-window-open.html',
'./integration-test/test-pages/scriptlets/config/prevent-window-open.json',
);
});

test('Prevent Fetch Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/prevent-fetch.html',
'./integration-test/test-pages/scriptlets/config/prevent-fetch.json',
);
});

test('Remove Node Text Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/remove-node-text.html',
'./integration-test/test-pages/scriptlets/config/remove-node-text.json',
);
});

test('Abort Current Inline Script Scriptlet', async ({ page }, testInfo) => {
await testPage(
page,
testInfo,
'scriptlets/pages/abort-current-inline-script.html',
'./integration-test/test-pages/scriptlets/config/abort-current-inline-script.json',
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"readme": "This config tests the abortCurrentInlineScript scriptlet",
"version": 1,
"unprotectedTemporary": [],
"features": {
"scriptlets": {
"exceptions": [],
"state": "enabled",
"settings": {
"scriptlets": [],
"conditionalChanges": [
{
"condition": [
{
"domain": "localhost"
},
{
"domain": "privacy-test-pages.site"
}
],
"patchSettings": [
{
"op": "add",
"path": "/scriptlets/-",
"value": {
"name": "abortCurrentInlineScript",
"attrs": {
"property": "document.createElement",
"search": "badScript"
}
}
}
]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"readme": "This config tests the abortOnPropertyRead scriptlet",
"version": 1,
"unprotectedTemporary": [],
"features": {
"scriptlets": {
"exceptions": [],
"state": "enabled",
"settings": {
"scriptlets": [],
"conditionalChanges": [
{
"condition": [
{
"domain": "localhost"
},
{
"domain": "privacy-test-pages.site"
}
],
"patchSettings": [
{
"op": "add",
"path": "/scriptlets/-",
"value": {
"name": "abortOnPropertyRead",
"attrs": {
"property": "testBadProperty"
}
}
}
]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"readme": "This config tests the abortOnPropertyWrite scriptlet",
"version": 1,
"unprotectedTemporary": [],
"features": {
"scriptlets": {
"exceptions": [],
"state": "enabled",
"settings": {
"scriptlets": [],
"conditionalChanges": [
{
"condition": [
{
"domain": "localhost"
},
{
"domain": "privacy-test-pages.site"
}
],
"patchSettings": [
{
"op": "add",
"path": "/scriptlets/-",
"value": {
"name": "abortOnPropertyWrite",
"attrs": {
"property": "testWriteProperty"
}
}
}
]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"readme": "This config tests the preventAddEventListener scriptlet",
"version": 1,
"unprotectedTemporary": [],
"features": {
"scriptlets": {
"exceptions": [],
"state": "enabled",
"settings": {
"scriptlets": [],
"conditionalChanges": [
{
"condition": [
{
"domain": "localhost"
},
{
"domain": "privacy-test-pages.site"
}
],
"patchSettings": [
{
"op": "add",
"path": "/scriptlets/-",
"value": {
"name": "preventAddEventListener",
"attrs": {
"typeSearch": "click",
"listenerSearch": "badListener"
}
}
}
]
}
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"readme": "This config tests the preventFetch scriptlet",
"version": 1,
"unprotectedTemporary": [],
"features": {
"scriptlets": {
"exceptions": [],
"state": "enabled",
"settings": {
"scriptlets": [],
"conditionalChanges": [
{
"condition": [
{
"domain": "localhost"
},
{
"domain": "privacy-test-pages.site"
}
],
"patchSettings": [
{
"op": "add",
"path": "/scriptlets/-",
"value": {
"name": "preventFetch",
"attrs": {
"propsToMatch": "url:/blocked-url"
}
}
}
]
}
]
}
}
}
}
Loading
Loading