Skip to content

Commit 3e8f627

Browse files
Merge pull request #12 from mukulboro/main
AI Enhancements, Ad-Blocking, and Performance Logging
2 parents bd67da9 + 4b28997 commit 3e8f627

10 files changed

Lines changed: 476 additions & 309 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Thumbs.db
3030
dist/
3131
coverage/
3232
build/
33+
test/
3334

3435
# Optional: lock files (if you want to avoid committing them)
3536
# package-lock.json
36-
# yarn.lock
37+
# yarn.lock
38+
bun.lock

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,5 @@ build/
6464
# Temporary folders
6565
tmp/
6666
temp/
67+
68+
bun.lock

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Breaking Changes
6+
- **Default AI Model Changed**: The default AI model has been switched from `gpt-4o` to `gemini-3-flash-preview` to make the CLI more accessible out of the box (Google provides a free tier for Gemini API keys). If you previously relied on the default `gpt-4o` and only had an `OPENAI_API_KEY` set, you may need to pass `--ai-model gpt-4o` explicitly.
7+
8+
### Changed
9+
- Improved `handleCookieConsent()` precision to avoid accidentally hiding non-banner layout elements.
10+
- Fixed an issue where the Adblocker plugin would register multiples times during `BrowserEngine` initialization.
11+
312
## 1.0.2 - 2025-08-18
413

514
### Added

README.md

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -104,60 +104,55 @@ npm install
104104
node src/cli.js https://example.com
105105
```
106106

107-
### OpenAI API Key Setup (Required for AI Features)
107+
### API Key Setup (Required for AI Features)
108108

109-
**🚨 IMPORTANT**: Users must set up their OpenAI API key in their terminal environment before using AI features. The package does NOT include pre-configured API keys.
109+
**🚨 IMPORTANT**: Users must set up an API key (Gemini or OpenAI) in their terminal environment before using AI features. The tool defaults to `gemini-3-flash-preview` as Google provides free API keys, making it more accessible.
110110

111-
#### **Step 1: Get OpenAI API Key**
111+
#### **Step 1: Get an API Key**
112112

113-
1. Visit [OpenAI Platform](https://platform.openai.com/api-keys)
114-
2. Create account and generate API key
115-
3. Copy your API key (starts with `sk-`)
113+
- **Gemini (Default)**: Get a free key from [Google AI Studio](https://aistudio.google.com/app/apikey)
114+
- **OpenAI (Alternative)**: Get a key from [OpenAI Platform](https://platform.openai.com/api-keys)
116115

117116
#### **Step 2: Set Environment Variable (REQUIRED)**
118117

119118
**Windows PowerShell:**
120119

121120
```powershell
122121
# Temporary (current session only)
123-
$env:OPENAI_API_KEY="sk-your-api-key-here"
122+
$env:GEMINI_API_KEY="AIzaSy..."
123+
# Or if using OpenAI:
124+
$env:OPENAI_API_KEY="sk-..."
124125
125126
# Permanent (recommended)
126-
[System.Environment]::SetEnvironmentVariable('OPENAI_API_KEY', 'sk-your-api-key-here', 'User')
127-
128-
# Verify setup
129-
echo $env:OPENAI_API_KEY
127+
[System.Environment]::SetEnvironmentVariable('GEMINI_API_KEY', 'AIzaSy...', 'User')
130128
```
131129

132130
**Windows Command Prompt:**
133131

134132
```cmd
135133
# Temporary (current session only)
136-
set OPENAI_API_KEY=sk-your-api-key-here
137-
138-
# Verify setup
139-
echo %OPENAI_API_KEY%
134+
set GEMINI_API_KEY=AIzaSy...
140135
```
141136

142137
**macOS/Linux (Bash/Zsh):**
143138

144139
```bash
145140
# Temporary (current session only)
146-
export OPENAI_API_KEY="sk-your-api-key-here"
141+
export GEMINI_API_KEY="AIzaSy..."
147142

148143
# Permanent (add to ~/.bashrc or ~/.zshrc)
149-
echo 'export OPENAI_API_KEY="sk-your-api-key-here"' >> ~/.bashrc
144+
echo 'export GEMINI_API_KEY="AIzaSy..."' >> ~/.bashrc
150145
source ~/.bashrc
151-
152-
# Verify setup
153-
echo $OPENAI_API_KEY
154146
```
155147

156148
#### **Alternative: Command Line Parameter**
157149

158150
```bash
159151
# Pass API key directly (not recommended for security)
160-
mirror-web-cli https://example.com --ai --openai-key "sk-your-key-here"
152+
# If using Gemini (default)
153+
mirror-web-cli https://example.com --ai --openai-key "AIzaSy..."
154+
# If using OpenAI
155+
mirror-web-cli https://example.com --ai --ai-model gpt-4o --openai-key "sk-..."
161156
```
162157

163158
#### **Step 3: Verify Setup**
@@ -172,9 +167,9 @@ mirror-web-cli https://example.com --ai --debug
172167

173168
**Requirements:**
174169

175-
-**OpenAI API keys only** (must start with `sk-`)
176-
-**GPT-4o model** for intelligent analysis
177-
-**Active OpenAI account** with billing setup
170+
-**Gemini AI API Key** (`AIzaSy...`) or **OpenAI API Key** (`sk-...`)
171+
-**gemini-3-flash-preview** (Default model) or **GPT-4o**
172+
-**Active account** with API access
178173
-**Terminal environment setup** (no pre-configured keys)
179174

180175
### Basic Usage (After Installation)
@@ -203,16 +198,17 @@ mirror-web-cli https://complex-site.com --debug
203198

204199
```bash
205200
# FIRST: Set up API key (see above section)
206-
export OPENAI_API_KEY="sk-your-api-key-here" # Linux/macOS
201+
export GEMINI_API_KEY="AIzaSy..." # Linux/macOS
207202
# or
208-
$env:OPENAI_API_KEY="sk-your-api-key-here" # Windows PowerShell
203+
$env:GEMINI_API_KEY="AIzaSy..." # Windows PowerShell
209204

210-
# THEN: Use AI features
205+
# THEN: Use AI features (defaults to gemini-3-flash-preview)
211206
mirror-web-cli https://example.com --ai
212207
# → Creates: ./example.com-ai-enhanced/
213208

214-
# AI + Clean mirroring
215-
mirror-web-cli https://complex-app.com --ai --clean
209+
# AI + Clean mirroring with OpenAI explicitly:
210+
export OPENAI_API_KEY="sk-..."
211+
mirror-web-cli https://complex-app.com --ai --ai-model gpt-4o --clean
216212
# → Creates: ./complex-app.com-ai-enhanced/
217213
```
218214

@@ -223,8 +219,8 @@ mirror-web-cli https://complex-app.com --ai --clean
223219
mirror-web-cli https://example.com --ai
224220

225221
# You'll see:
226-
# ⚠️ AI features requested but no OPENAI_API_KEY found
227-
# Add OPENAI_API_KEY to your environment...
222+
# ⚠️ AI analysis API key not found. AI analysis will be disabled.
223+
# Set GEMINI_API_KEY environment variable to enable AI features...
228224
# Continuing without AI features...
229225
```
230226

@@ -376,7 +372,10 @@ Arguments:
376372
Options:
377373
-o, --output <dir> Custom output directory (default: domain name)
378374
--clean Remove tracking scripts and analytics
375+
--block-ads Block advertisements using adblocker plugin
376+
--block-cookies Automatically remove and block cookie consent banners
379377
--ai Enable AI-powered analysis (requires OpenAI API key)
378+
--ai-model <model> AI model to use (default: gemini-3-flash-preview)
380379
--openai-key <key> OpenAI API key for AI features (or set OPENAI_API_KEY env var)
381380
--debug Enable detailed debug logging
382381
--timeout <ms> Page load timeout in milliseconds (default: 120000)
@@ -385,14 +384,13 @@ Options:
385384
-V, --version Show version number
386385
```
387386

388-
### OpenAI API Key Priority
387+
### API Key Priority
389388

390-
The tool checks for OpenAI API keys in this order:
389+
The tool checks for API keys in this order:
391390

392-
1. `--openai-key` command line parameter
393-
2. `OPENAI_API_KEY` environment variable
391+
1. `--openai-key` command line parameter (handles both Gemini and OpenAI keys)
392+
2. `GEMINI_API_KEY` (if default Gemini model is used) or `OPENAI_API_KEY` environment variable
394393
3. If neither is found, AI features are disabled with a helpful message
395-
4. Keys must start with `sk-` (validated automatically)
396394

397395
## 🏗️ Framework Support
398396

@@ -443,24 +441,24 @@ mirror-web-cli https://shop.example.com --debug --clean
443441
# → Creates: ./shop.example.com-standard/ with detailed logging, removes analytics
444442
```
445443

446-
### AI-Powered Analysis (OpenAI)
444+
### AI-Powered Analysis (Gemini/OpenAI)
447445

448446
**Windows PowerShell:**
449447

450448
```powershell
451449
# Set environment variable first
452-
$env:OPENAI_API_KEY="sk-proj-your-openai-key-here"
450+
$env:GEMINI_API_KEY="AIzaSy..."
453451
mirror-web-cli https://complex-app.com --ai --clean
454-
# → Creates: ./complex-app.com-ai-enhanced/ with OpenAI GPT-4o framework analysis
452+
# → Creates: ./complex-app.com-ai-enhanced/ with AI framework analysis
455453
```
456454

457455
**macOS/Linux:**
458456

459457
```bash
460458
# Set environment variable first
461-
export OPENAI_API_KEY="sk-proj-your-openai-key-here"
459+
export GEMINI_API_KEY="AIzaSy..."
462460
mirror-web-cli https://complex-app.com --ai --clean
463-
# → Creates: ./complex-app.com-ai-enhanced/ with OpenAI GPT-4o framework analysis
461+
# → Creates: ./complex-app.com-ai-enhanced/ with AI framework analysis
464462
```
465463

466464
**Cross-platform (using CLI parameter):**

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
"node-fetch": "^3.3.2",
5959
"openai": "^4.67.3",
6060
"puppeteer": "^24.16.2",
61+
"puppeteer-extra": "^3.3.6",
62+
"puppeteer-extra-plugin-adblocker": "^2.13.6",
6163
"sharp": "^0.33.5"
6264
},
6365
"repository": {

src/ai/ai-analyzer.js

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,52 @@ dotenv.config();
99
* AI-Powered Website Analysis using OpenAI GPT-4o
1010
*/
1111
export class AIAnalyzer {
12-
constructor() {
12+
constructor(aiModel = 'gpt-4o') {
1313
this.openai = null;
1414
this.isEnabled = false;
15+
this.aiModel = aiModel;
1516
this.initializeOpenAI();
1617
}
1718

1819
initializeOpenAI() {
19-
const apiKey = process.env.OPENAI_API_KEY;
20+
const isGemini = this.aiModel.toLowerCase().includes('gemini');
21+
let apiKey = isGemini ? process.env.GEMINI_API_KEY : process.env.OPENAI_API_KEY;
2022

23+
// Fallback if specific key is missing
2124
if (!apiKey) {
25+
apiKey = process.env.OPENAI_API_KEY || process.env.GEMINI_API_KEY;
26+
}
27+
28+
if (!apiKey) {
29+
const keyName = isGemini ? 'GEMINI_API_KEY' : 'OPENAI_API_KEY';
2230
console.log(
2331
chalk.yellow(
24-
'⚠️ OpenAI API key not found. AI analysis will be disabled.',
32+
`⚠️ AI analysis API key not found. AI analysis will be disabled.`,
2533
),
2634
);
2735
console.log(
2836
chalk.gray(
29-
' Set OPENAI_API_KEY environment variable to enable AI features.',
37+
` Set ${keyName} environment variable to enable AI features.`,
3038
),
3139
);
3240
return;
3341
}
3442

3543
try {
36-
this.openai = new OpenAI({ apiKey });
44+
const config = { apiKey };
45+
46+
// Use Gemini OpenAI-compatible endpoint if model is gemini or GEMINI_API_KEY is used
47+
if (isGemini || process.env.GEMINI_API_KEY === apiKey) {
48+
config.baseURL = 'https://generativelanguage.googleapis.com/v1beta/openai/';
49+
console.log(chalk.green(`✅ AI analysis enabled with Gemini model: ${this.aiModel}`));
50+
} else {
51+
console.log(chalk.green(`✅ AI analysis enabled with OpenAI model: ${this.aiModel}`));
52+
}
53+
54+
this.openai = new OpenAI(config);
3755
this.isEnabled = true;
38-
console.log(chalk.green('✅ AI analysis enabled with OpenAI GPT-4o'));
3956
} catch (error) {
40-
console.log(chalk.red('❌ Failed to initialize OpenAI:'), error.message);
57+
console.log(chalk.red('❌ Failed to initialize AI client:'), error.message);
4158
}
4259
}
4360

@@ -72,7 +89,7 @@ export class AIAnalyzer {
7289
);
7390

7491
const response = await this.openai.chat.completions.create({
75-
model: 'gpt-4o',
92+
model: this.aiModel,
7693
messages: [
7794
{
7895
role: 'system',
@@ -225,7 +242,7 @@ Provide actionable optimization steps in JSON format:
225242
}`;
226243

227244
const response = await this.openai.chat.completions.create({
228-
model: 'gpt-4o',
245+
model: this.aiModel,
229246
messages: [
230247
{
231248
role: 'system',

0 commit comments

Comments
 (0)