I'm trying to inject a few local .js files onto pages so they can do some tidying before I save the page HTML. Locally, it works well like this:
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const SINGLE_FILES = [
'single-file-bootstrap.js',
'single-file-frames.js',
'single-file-hooks-frames.js',
'single-file.js'
];
export const SINGLE_FILE_PATHS = SINGLE_FILES.map(file => path.join(__dirname, 'single-file', file));
export async function addScriptsToPage(page: Page) {
try {
for (const scriptPath of SINGLE_FILE_PATHS) {
await page.addScriptTag({ path: scriptPath });
}
} catch(e) {
console.error('Error adding scripts to page', e);
return { success: false, error: e };
}
return { success: true };
}
But when i try to run this on the apify platform, I get "No Such File Or Directory" errors. How can i reference files from my package on the apify platform so I can inject them into a page?