New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

webext-content-scripts

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webext-content-scripts - npm Package Compare versions

Comparing version 2.7.1 to 2.7.2

2

index.d.ts
import type { ContentScript, ExtensionFileOrCode, RunAt } from './types.js';
export * from './types.js';
export type * from './types.js';
interface Target {

@@ -4,0 +4,0 @@ tabId: number;

import chromeP from 'webext-polyfill-kinda';
import { patternToRegex } from 'webext-patterns';
export * from './types.js';
const gotScripting = Boolean(globalThis.chrome?.scripting);

@@ -27,2 +26,18 @@ function castTarget(target) {

}
function normalizeFiles(files, seen = []) {
return files
.map(file => typeof file === 'string' ? { file } : file)
.filter(content => {
if ('code' in content) {
return true;
}
const file = typeof content === 'string' ? content : content.file;
if (seen.includes(file)) {
console.debug(`Duplicated file not injected: ${file}`);
return false;
}
seen.push(file);
return true;
});
}
const nativeFunction = /^function \w+\(\) {[\n\s]+\[native code][\n\s]+}/;

@@ -57,7 +72,6 @@ export async function executeFunction(target, function_, ...arguments_) {

export async function insertCSS({ tabId, frameId, files, allFrames, matchAboutBlank, runAt, }, { ignoreTargetErrors } = {}) {
const everyInsertion = Promise.all(files.map(async (content) => {
if (typeof content === 'string') {
content = { file: content };
}
const normalizedFiles = normalizeFiles(files);
const everyInsertion = Promise.all(normalizedFiles.map(async (content) => {
if (gotScripting) {
// One file at a time, according to the types
return chrome.scripting.insertCSS({

@@ -94,3 +108,3 @@ target: {

export async function executeScript({ tabId, frameId, files, allFrames, matchAboutBlank, runAt, }, { ignoreTargetErrors } = {}) {
const normalizedFiles = files.map(file => typeof file === 'string' ? { file } : file);
const normalizedFiles = normalizeFiles(files);
if (gotScripting) {

@@ -153,20 +167,25 @@ assertNoCode(normalizedFiles);

async function injectContentScriptInSpecificTarget({ frameId, tabId, allFrames }, scripts, options = {}) {
const injections = castArray(scripts).flatMap(script => [
insertCSS({
tabId,
frameId,
allFrames,
files: script.css ?? [],
matchAboutBlank: script.matchAboutBlank ?? script.match_about_blank,
runAt: script.runAt ?? script.run_at,
}, options),
executeScript({
tabId,
frameId,
allFrames,
files: script.js ?? [],
matchAboutBlank: script.matchAboutBlank ?? script.match_about_blank,
runAt: script.runAt ?? script.run_at,
}, options),
]);
const seen = [];
const injections = castArray(scripts).flatMap(script => {
const css = normalizeFiles(script.css ?? [], seen);
const js = normalizeFiles(script.js ?? [], seen);
return [
css.length > 0 && insertCSS({
tabId,
frameId,
allFrames,
files: css,
matchAboutBlank: script.matchAboutBlank ?? script.match_about_blank,
runAt: script.runAt ?? script.run_at,
}, options),
js.length > 0 && executeScript({
tabId,
frameId,
allFrames,
files: js,
matchAboutBlank: script.matchAboutBlank ?? script.match_about_blank,
runAt: script.runAt ?? script.run_at,
}, options),
];
});
await Promise.all(injections);

@@ -173,0 +192,0 @@ }

{
"name": "webext-content-scripts",
"version": "2.7.1",
"version": "2.7.2",
"description": "Utility functions to inject content scripts in WebExtensions, for Manifest v2 and v3",

@@ -5,0 +5,0 @@ "keywords": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc