-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinspect-returns-detail.js
More file actions
176 lines (153 loc) · 5.54 KB
/
Copy pathinspect-returns-detail.js
File metadata and controls
176 lines (153 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* Detailed Return Policy Inspector
*
* Scrolls to product details and extracts ALL return-related information
*/
const puppeteer = require('puppeteer');
const TEST_URL = 'https://www.amazon.de/-/en/AlloverPower-E61-Group-Head-Coffee/dp/B0BNQ66ZN1';
async function inspectReturns() {
console.log('🔍 Inspecting return policy details...\n');
const browser = await puppeteer.launch({
headless: false,
args: ['--no-sandbox'],
defaultViewport: { width: 1400, height: 900 }
});
const page = await browser.newPage();
await page.goto(TEST_URL, { waitUntil: 'networkidle2', timeout: 30000 });
// Handle cookies
try {
const acceptButton = await page.waitForSelector('button[data-action="accept"]', { timeout: 3000 });
if (acceptButton) {
await acceptButton.click();
await new Promise(resolve => setTimeout(resolve, 1000));
}
} catch (e) {}
// Wait for page to load
await new Promise(resolve => setTimeout(resolve, 2000));
// Extract comprehensive return info
const returnData = await page.evaluate(() => {
const data = {
freeReturnsBadge: null,
deliveryBlockHTML: null,
returnPolicyText: [],
productDetailReturns: null,
allReturnMentions: []
};
// Check for FREE Returns badge specifically
const possibleBadges = [
'#mir-layout-DELIVERY_BLOCK',
'[data-feature-name="deliveryBlock"]',
'[data-feature-name="returns"]'
];
possibleBadges.forEach(selector => {
const elem = document.querySelector(selector);
if (elem) {
const html = elem.innerHTML;
const text = elem.innerText;
if (text.toLowerCase().includes('return')) {
data.deliveryBlockHTML = html;
data.freeReturnsBadge = {
selector: selector,
text: text,
hasFREE: text.includes('FREE Returns') || text.includes('FREE returns')
};
}
}
});
// Look for return policy in structured data
const detailsSections = document.querySelectorAll('#productDetails_detailBullets_sections1 tr, #productDetails_db_sections tr');
detailsSections.forEach(row => {
const th = row.querySelector('th');
const td = row.querySelector('td');
if (th && td) {
const key = th.textContent.trim().toLowerCase();
if (key.includes('return') || key.includes('rück')) {
data.productDetailReturns = {
label: th.textContent.trim(),
value: td.textContent.trim()
};
}
}
});
// Find ALL text nodes mentioning returns
function getAllText(node) {
let text = '';
if (node.nodeType === Node.TEXT_NODE) {
text = node.textContent.trim();
} else if (node.nodeType === Node.ELEMENT_NODE) {
for (let child of node.childNodes) {
text += getAllText(child) + ' ';
}
}
return text;
}
const bodyText = getAllText(document.body);
const sentences = bodyText.split(/[.!?\n]/);
sentences.forEach(sentence => {
const lower = sentence.toLowerCase().trim();
if ((lower.includes('return') || lower.includes('rück')) &&
sentence.trim().length > 10 &&
sentence.trim().length < 200) {
data.allReturnMentions.push(sentence.trim());
}
});
return data;
});
console.log('━'.repeat(70));
console.log('📍 FREE RETURNS BADGE');
console.log('━'.repeat(70));
if (returnData.freeReturnsBadge) {
console.log('✅ FOUND:');
console.log(' Selector:', returnData.freeReturnsBadge.selector);
console.log(' Contains "FREE Returns":', returnData.freeReturnsBadge.hasFREE ? 'YES ✅' : 'NO ❌');
console.log(' Full text:');
console.log(' ' + returnData.freeReturnsBadge.text.split('\n').join('\n '));
} else {
console.log('❌ NOT FOUND');
}
console.log('\n' + '━'.repeat(70));
console.log('📊 PRODUCT DETAILS - Return Policy');
console.log('━'.repeat(70));
if (returnData.productDetailReturns) {
console.log('✅ FOUND:');
console.log(' Label:', returnData.productDetailReturns.label);
console.log(' Value:', returnData.productDetailReturns.value);
} else {
console.log('❌ NOT FOUND in product details table');
}
console.log('\n' + '━'.repeat(70));
console.log('💬 ALL RETURN MENTIONS ON PAGE');
console.log('━'.repeat(70));
const uniqueMentions = [...new Set(returnData.allReturnMentions)].filter(m => m.length > 0);
if (uniqueMentions.length === 0) {
console.log('❌ No return mentions found');
} else {
uniqueMentions.slice(0, 15).forEach((mention, i) => {
console.log(`${i + 1}. ${mention}`);
});
if (uniqueMentions.length > 15) {
console.log(`... and ${uniqueMentions.length - 15} more mentions`);
}
}
// Scroll to product details
await page.evaluate(() => {
const details = document.querySelector('#productDetails_detailBullets_sections1') ||
document.querySelector('#detailBullets_feature_div');
if (details) {
details.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
});
await new Promise(resolve => setTimeout(resolve, 2000));
// Take screenshot of product details area
await page.screenshot({
path: '/tmp/returns-detail.jpg',
type: 'jpeg',
quality: 85,
fullPage: false
});
console.log('\n📸 Screenshot: /tmp/returns-detail.jpg');
console.log('\n👀 Browser stays open for inspection - close manually');
await new Promise(resolve => setTimeout(resolve, 15000));
await browser.close();
}
inspectReturns().catch(console.error);