Skip to content

Commit

Permalink
Implement (faulty) detection for when to hide/show the button
Browse files Browse the repository at this point in the history
Seems now blocked on the navigation.canGoBack API being implemented, so waiting on https://bugzilla.mozilla.org/show_bug.cgi?id=1777171
  • Loading branch information
Skeletonxf committed Nov 10, 2024
1 parent ff59310 commit fa5dd24
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/duplicate-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,33 @@ export default class DuplicateTab {
return true
}
if (data.getPageData === true) {
let oldTabHasHistory = false
try {
let injectionResult = (await browser.scripting.executeScript({
target: {
tabId: id
},
// The same code from the file as a function doesn't
// seem able to return the last expression and is always
// undefined, so we need to use a file for this even
// though we just need to execute a single line
files: [ 'src/get-history.js' ]
}))[0]
// Length is 1 when history is empty due to current tab
// FIXME: This doesn't work properly if there are pages
// forward of the current page, as they are included
// in the history too even when we have nothing to go back
// to. `navigation.canGoBack` seems what we actually want
// but it has not been implemented at the time of writing
oldTabHasHistory = injectionResult.result > 1
} catch (error) {
console.error('Error checking for history in original tab', error)
}
return {
url: url,
oldTabIsIncognito: incognito,
allowedIncognitoAccess: await browser.extension.isAllowedIncognitoAccess()
allowedIncognitoAccess: await browser.extension.isAllowedIncognitoAccess(),
oldTabHasHistory: oldTabHasHistory,
}
}
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions src/get-history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
window.history.length
7 changes: 5 additions & 2 deletions src/page/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ buttons.forEach((b) => b.deleter = new IdempotentElementDeleter(b.element))
type: 'page',
getPageData: true
})
const { url } = response
const { oldTabIsIncognito } = response
const { url, oldTabIsIncognito, oldTabHasHistory } = response

document.getElementById('page-url').textContent += (url)
document.getElementById('page-url-suffix').classList.remove('hidden')
Expand Down Expand Up @@ -89,6 +88,10 @@ buttons.forEach((b) => b.deleter = new IdempotentElementDeleter(b.element))
let navigateBackTabNav = document.querySelector('#normal-and-navigate-back-tab-name')
navigateBackTabNav.textContent = 'Private Browsing'
}
if (!oldTabHasHistory) {
// nothing to navigate back with so delete the option
buttons.get('normal-and-navigate-back').deleter.run()
}
const { allowedIncognitoAccess } = response
if (allowedIncognitoAccess === false) {
// the only case that needs user notification is moving
Expand Down

0 comments on commit fa5dd24

Please sign in to comment.