Skip to content

Commit

Permalink
feat(#2): prevent new history
Browse files Browse the repository at this point in the history
  • Loading branch information
igorlogius committed Jan 4, 2024
1 parent f1e72f5 commit feebbe8
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
Open a tab, page, link or bookmark in a new empty temporary container

More Infos about containers: https://support.mozilla.org/en-US/kb/how-use-firefox-containers
Open a tab, page, link or bookmark in a new empty temporary container More Infos
about containers:
https://support.mozilla.org/en-US/kb/how-use-firefox-containers

<b>Short Demo Video:</b>

https://github.com/igorlogius/open-in-temp-container/assets/67047467/996f18a0-f95f-40ca-9082-d690d4a95b35

<b>Usage/Features</b>
<ul>
<li>context menu on various elements - toolbar button - custum shortcut</li>
<li>Note: to enable the bookmark entry, enable the optional permission in the addon settings</li>
<li>context menu on various elements - toolbar button - custum shortcut</li>
<li>
To enable the bookmark entry, enable the optional bookmark permission in the
addon settings
</li>
<li>
<b>History Deletion / Prevention </b>
By enabeling the history permission, the temporary container tabs will
prevent the creation of new history items for sites/urls which never been
visited before. (aka. dont have any existing history entries yet). This
method was choosen, because it is non speculative but still less potentially
destructive than the alternative of deleting all visits to a visited urls,
like how the `temporary containers` addons Delete History works.
</li>
</ul>

<b>Notes:</b>
Expand Down
22 changes: 17 additions & 5 deletions about.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
Open a tab, page, link or bookmark in a new empty temporary container

More Infos about containers: https://support.mozilla.org/en-US/kb/how-use-firefox-containers
Open a tab, page, link or bookmark in a new empty temporary container More Infos
about containers:
https://support.mozilla.org/en-US/kb/how-use-firefox-containers

<b>Short Demo Video:</b>

https://github.com/igorlogius/open-in-temp-container/assets/67047467/996f18a0-f95f-40ca-9082-d690d4a95b35

<b>Usage/Features</b>
<ul>
<li>context menu on various elements - toolbar button - custum shortcut</li>
<li>Note: to enable the bookmark entry, enable the optional permission in the addon settings</li>
<li>context menu on various elements - toolbar button - custum shortcut</li>
<li>
To enable the bookmark entry, enable the optional bookmark permission in the
addon settings
</li>
<li>
<b>History Deletion / Prevention </b>
By enabeling the history permission, the temporary container tabs will
prevent the creation of new history items for sites/urls which never been
visited before. (aka. dont have any existing history entries yet). This
method was choosen, because it is non speculative but still less potentially
destructive than the alternative of deleting all visits to a visited urls,
like how the `temporary containers` addons Delete History works.
</li>
</ul>
44 changes: 44 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,47 @@ browser.commands.onCommand.addListener(async (command) => {
}
}
});

async function handleUpdated(tabId, changeInfo, tabInfo) {
if (changeInfo.status === "complete") {
if (tabInfo.url.startsWith("http")) {
try {
const container = await browser.contextualIdentities.get(
tabInfo.cookieStoreId
);
if (container.name.startsWith("Temp")) {
const visits = await browser.history.getVisits({
url: tabInfo.url,
});

if (visits.length === 1) {
browser.history.deleteUrl({
url: tabInfo.url,
});
//console.debug("removed url", tabInfo.url);
}
}
} catch (e) {
// noop
}
}
}
}

var testPermissions1 = {
permissions: ["history"],
};

async function handlePermissionChange(permissions) {
if (await browser.permissions.contains(testPermissions1)) {
//console.debug("added handleUpdated listener");
await browser.tabs.onUpdated.addListener(handleUpdated);
} else {
await browser.tabs.onUpdated.removeListener(handleUpdated);
//console.debug("removed handleUpdated listener");
}
}
browser.permissions.onAdded.addListener(handlePermissionChange);
browser.permissions.onRemoved.addListener(handlePermissionChange);

handlePermissionChange();
6 changes: 2 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
"menus",
"tabs"
],
"optional_permissions": [
"bookmarks"
],
"version": "1.1.11"
"optional_permissions": ["bookmarks", "history"],
"version": "1.1.12"
}

0 comments on commit feebbe8

Please sign in to comment.