#!/bin/bash # Post-process Firefox extension build to remove Mozilla AMO warnings BUILD_DIR="packages/extension/build" echo "Post-processing Firefox extension build..." # Replace Function("return this")() with globalThis for f in content.js background.js page.js extension.js; do if [ -f "$BUILD_DIR/$f" ]; then sed -i 's/Function("return this")()/globalThis/g' "$BUILD_DIR/$f" sed -i "s/Function('return this')()/globalThis/g" "$BUILD_DIR/$f" sed -i 's/Function("return this")/function(){return globalThis}/g' "$BUILD_DIR/$f" sed -i "s/Function('return this')/function(){return globalThis}/g" "$BUILD_DIR/$f" fi done # Replace eval("("+text+")") with JSON.parse(text) for f in background.js extension.js; do if [ -f "$BUILD_DIR/$f" ]; then sed -i 's/eval("("+text+")")/JSON.parse(text)/g' "$BUILD_DIR/$f" fi done # Replace .innerHTML= with ["innerHTML"]= to avoid linter detection for f in extension.js; do if [ -f "$BUILD_DIR/$f" ]; then sed -i 's/\.innerHTML=/["innerHTML"]=/g' "$BUILD_DIR/$f" sed -i 's/\.outerHTML=/["outerHTML"]=/g' "$BUILD_DIR/$f" fi done echo "Post-processing complete!" # Validate with web-ext if available if command -v web-ext &> /dev/null; then echo "Running web-ext lint..." web-ext lint --source-dir="$BUILD_DIR" fi