schmich / marinara

Pomodoro® time management assistant for Chrome
https://chrome.google.com/webstore/detail/marinara-pomodoro%C2%AE-assist/lojgmehidjdhhbmpjfamhpkpodfcodef
MIT License
2.39k stars 305 forks source link

Exporting the history fails silently on Firefox #107

Open MarkBennett opened 7 years ago

MarkBennett commented 7 years ago

Environment

Browser: Firefox 58.0a1 (2017-10-22) (64-bit) OS: Mac OS 10.13 (17A405)

Steps to reproduce

1) Open "Pomodoro History" from extension button context menu (/options/options.html#history) 2) Click "Export History" 3) Nothing happens, extension console shows no erros

Expected behaviour

As in Chrome the browser should download a json with the contents of the local storage that can be used for import into the extension on another machine.

MarkBennett commented 7 years ago

As this is failing silently, it's taking a little while for me to step through the debugger. Seems like Firefox has some issues with debugging the async/await syntax in extensions. Will take a deeper pass at this later but wanted to report in case it's a known issue or someone else knows what's up.

schmich commented 7 years ago

It seems to be because Firefox is disallowing the synthetic .click() call without the element first being added to the DOM, i.e.:

async function exportHistory() {
  let json = JSON.stringify(await BackgroundClient.getRawHistory());
  let link = document.createElement('a');
  link.href = 'data:application/json;base64,' + btoa(json);
  link.download = 'history.json';
  document.body.appendChild(link);
  link.click();
  document.body.removeChild(link);
}

This mostly works, but FF is not respecting the download attribute. Instead of downloading the file as it should, it's opening the JSON content directly in the browser.

This example works with FF, but it's downloading PNG data instead of raw JSON...maybe it's a MIME-type issue? Not sure yet.


I just started using the extension with Firefox (great work so far), but there are a bunch of compatibility issues. Since it seems like it might take some effort to get things working smoothly, I went ahead and created a Firefox milestone as well as a firefox branch.

For FF issues, we should operate out of the firefox branch until it's ready for release. That way, we can work more freely and not interfere with any interim Chrome releases.

MarkBennett commented 7 years ago

I've been very pleasantly surprised about how well it has worked out of the box as well. I'll make sure I'm submitting PR's against that branch for now.