diff --git a/harextract.html b/harextract.html
index 6dfd27a..ffdc5a6 100644
--- a/harextract.html
+++ b/harextract.html
@@ -281,6 +281,23 @@
let encoding = data[ent.id].response.content.encoding;
if (encoding != 'base64')
throw new Error(`Unsupported encoding for ${ent.name} (${ent.id}): ${encoding}`);
+ if (zip.file(filepath)) {
+ // file already exists in the zip so we need to find a unique name for it
+ // split the full path into the folder/directory part and the filename part
+ const slashIdx = filepath.lastIndexOf('/');
+ const dir = slashIdx >= 0 ? filepath.substring(0, slashIdx + 1) : '';
+ const filename = slashIdx >= 0 ? filepath.substring(slashIdx + 1) : filepath;
+ // split the filename into base and extension so we can stick the suffix in before the dot
+ // we use lastIndexOf on just the filename so dots in directory names dont mess things up
+ const dotIdx = filename.lastIndexOf('.');
+ const base = dotIdx >= 0 ? filename.substring(0, dotIdx) : filename;
+ const ext = dotIdx >= 0 ? filename.substring(dotIdx) : '';
+ // start at 2 since the original file already took the unsuffixed slot
+ let counter = 2;
+ // keep incrementing until we find a name thats not already in the zip
+ while (zip.file(`${dir}${base}_${counter}${ext}`)) counter++;
+ filepath = `${dir}${base}_${counter}${ext}`;
+ }
zip.file(filepath, data[ent.id].response.content.text, { base64: true });
} catch (e) {
console.log(e);