Skip to content

Commit

Permalink
fix: prevent iframe load/unload from adding to history
Browse files Browse the repository at this point in the history
  • Loading branch information
micwallace committed Nov 24, 2023
1 parent aca32cd commit 02e0b78
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CardModal {
return (
<Host class="view-container" style={{display: "none"}}>
<button class="close-btn" onClick={() => {
document.location.hash = "#";
//document.location.hash = "#";
this.tokenScript.getViewController().unloadTokenCard();
}}>X
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export class CardPopover implements IViewBinding {
async unloadTokenView() {
await this.dialog.closeDialog();
this.currentCard = null;
this.iframe.src = "";
document.location.hash = "#";
this.iframe.contentWindow.location.replace("");
history.replaceState(undefined, undefined, "/");
}

viewError(error: Error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class TokensGrid {
// TODO: Remove index - all cards should have a unique name but some current tokenscripts don't match the schema
// TODO: set only card param rather than updating the whole hash query
if (card.view)
document.location.hash = "#card=" + (card.name ?? cardIndex);
history.replaceState(undefined, undefined, "#card=" + (card.name ?? cardIndex));
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class NewViewer {
// Import completed successfully, add tokenscript to myTokenScripts
tsMeta = await this.addFormSubmit("url", {tsId: tokenScript.getSourceInfo().tsId, image: definition.meta.image});

document.location.hash = "";
//document.location.hash = "";
window.history.replaceState({}, document.title, "/");

this.showToast.emit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ export abstract class AbstractViewBinding implements IViewBinding {

async unloadTokenView() {
this.currentCard = null;
this.iframe.src = "";
this.actionBar.style.display = "none";
document.location.hash = "#";
this.iframe.contentWindow.location.replace("");
history.replaceState(undefined, undefined, "/");
}

protected showLoader() {
Expand All @@ -75,7 +75,8 @@ export abstract class AbstractViewBinding implements IViewBinding {

if (card.isUrlView) {

iframe.src = card.url;
//iframe.src = card.url;
iframe.contentWindow.location.replace(card.url);

} else {
const html = await card.renderViewHtml();
Expand All @@ -84,7 +85,8 @@ export abstract class AbstractViewBinding implements IViewBinding {

const urlFragment = card.urlFragment;

iframe.src = URL.createObjectURL(blob) + (urlFragment ? "#" + urlFragment : "");
const url = URL.createObjectURL(blob) + (urlFragment ? "#" + urlFragment : "");
iframe.contentWindow.location.replace(url);

// TODO: try src-doc method
}
Expand Down

0 comments on commit 02e0b78

Please sign in to comment.