Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
BatMiles committed Aug 30, 2024
1 parent ab9dd0c commit d779a70
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/fb-pixel-lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const FB_ADVANCED_MATCHING_PARAMETERS = {
'ud[country]': 'Country',
'ud[external_id]': 'An ID from another database.'
};

// https://web.archive.org/web/20200519201636/https://developers.facebook.com/docs/facebook-pixel/reference
export const FB_STANDARD_EVENTS = [
{
Expand Down Expand Up @@ -98,4 +99,3 @@ export const FB_STANDARD_EVENTS = [
eventName: 'ViewContent'
}
];
// const parseFacebookPixesParamete
4 changes: 1 addition & 3 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import { createLogger, format, transports } from 'winston';

export const getLogger = ({ outDir = '', quiet = false }) => {
const log_transports = [];
let filename;

log_transports.push(
new transports.Console({
level: 'info',
silent: quiet
})
);

filename = outDir ? path.join(outDir, 'inspection-log.ndjson') : tmpNameSync({ postfix: '-log.ndjson' });
const filename = outDir ? path.join(outDir, 'inspection-log.ndjson') : tmpNameSync({ postfix: '-log.ndjson' });

log_transports.push(
new transports.File({
Expand Down
2 changes: 2 additions & 0 deletions src/pptr-utils/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs';
import path from 'path';
import { Page } from 'puppeteer';
import { promisify } from 'util';

const writeFile = promisify(fs.writeFile);

export const savePageContent = async (index, outDir, page: Page, screenshot = true) => {
Expand All @@ -17,6 +18,7 @@ export const savePageContent = async (index, outDir, page: Page, screenshot = tr
console.log(`couldnt save page content: ${JSON.stringify(error)}`);
}
};

/**
* Default Puppeteer options for dev
*/
Expand Down
13 changes: 1 addition & 12 deletions src/pptr-utils/interaction-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ export const fillForms = async (page: Page, timeout = 6000) => {
const timeoutPromise = new Promise(resolve => {
setTimeout(() => {
if (isInteracting) {
// console.log('Interaction ongoing. Waiting for safe exit.');
return;
}
// console.log('Timeout reached. Exiting fillForms().');
resolve('Timeout');
}, timeout);
});
Expand All @@ -59,52 +57,42 @@ export const fillForms = async (page: Page, timeout = 6000) => {
if (!page.isClosed()) {
isInteracting = true;

// console.log(`Inspecting element ${count}`);
if (count > 100) {
break;
}
count += 1;

const pHandle = await el.getProperty('type');
const pValue = await pHandle.jsonValue();
// console.log(`Input is type ${pValue}`);

const autoCompleteHandle = await el.getProperty('autocomplete');
const autoCompleteValue = (await autoCompleteHandle.jsonValue()) as string;
// console.log(`Autocomplete attribute is: ${autoCompleteValue}`);
let autoCompleteKeys = [];

// console.log('Checking autocomplete value');
if (autoCompleteValue) {
if (autoCompleteValue.includes('cc-name')) {
// console.log('Autocomplete includes cc-name.');
autoCompleteKeys = ['cc-name'];
} else {
// console.log('Autocomplete does not include cc-name.');
autoCompleteKeys = Object.keys(DEFAULT_INPUT_VALUES).filter(k => (autoCompleteValue as string).includes(k));
}
}

if (pValue === 'submit' || pValue === 'hidden') {
// console.log('Type is either submit or hidden.');
continue;
} else if (autoCompleteKeys.length > 0) {
// console.log('Autocomplete keys > 0');
await el.focus();
await page.keyboard.press('Tab', {
delay: 100
});
await el.press('Backspace');
await page.keyboard.type(DEFAULT_INPUT_VALUES[autoCompleteKeys[0] as string]);
} else if (Object.keys(DEFAULT_INPUT_VALUES).includes(pValue as string)) {
// console.log('Default input values includes pValue');
await el.focus();
await page.keyboard.press('Tab', {
delay: 100
});
await el.press('Backspace');
await page.keyboard.type(DEFAULT_INPUT_VALUES[pValue as string]);
// console.log(' ... done with test');
}
isInteracting = false;
} else {
Expand Down Expand Up @@ -137,6 +125,7 @@ export const autoScroll = async page => {
const distance = 150;
const COUNT_MAX = 5;
let count = 0;

const timer = setInterval(() => {
const scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export interface LinkObject {
innerHtml: string;
innerText: string;
}

export const SESSION_RECORDERS_LIST = [
'mc.yandex.ru/metrika/watch.js',
'mc.yandex.ru/metrika/tag.js',
Expand Down

0 comments on commit d779a70

Please sign in to comment.