3

When you've just sent a form then refresh, if you haven't used the Post/Redirect/Get pattern, Firefox will ask you if you want to resend your form data. If you click Resend, the page would normally reload and the form processing code would do its thing again.

In production, usually, I redirect so this doesn't happen. While developing, though, it can be very useful to be able to refresh and see my debug dumps with the same post data as my code changes, without having to fill the form again or use a tool such as Postman. Just fill the form, die() before the redirect, and test away.

In the last few months, it seems something changed, and Firefox now only pretends to resend the data on a refresh. It still asks me, but even when the following code is the very first thing executed, $_POST is an empty array.

<?php
  echo '<pre>';
  var_dump($_POST);
  echo '</pre>';
  die();
?>

Meanwhile, following the same steps on Chrome does give me back my $_POST array like it used to.

I was away from work for several months, so I'm not sure what changed, but since using Firefox in Safe Mode (without add-ons) yields the same result, I'm almost sure the issue is there. I use Firefox 75 on Mac.

Is there a hidden preference that changes the behaviour of resending POST data on refresh? Can I fix this?

7
  • 2
    Now it doesn't ask, just sends a GET request to the same URL. The old behaviour was much more useful.
    – Jake
    Oct 13, 2020 at 23:46
  • Agreed. It would be nice if there were a way to change it back.
    – Ariane
    Oct 15, 2020 at 12:59
  • Seems it is dependent on something that JavaScript can control, but not clear what. Simple test setup and expected prompt about resubmitting appears. But something implemented in WordPress admin and POST request is resubmitted as GET without prompt - console log shows clearly it was not PRG. With JavaScript disabled, in both cases, a prompt appears before the POST request is repeated.
    – Jake
    Oct 16, 2020 at 1:53
  • It seems use of History.replaceState can prevent POST request being repeated.
    – Jake
    Oct 16, 2020 at 1:56
  • Maybe that's what WordPress does, somewhere, as part of its security?
    – Ariane
    Oct 21, 2020 at 15:14

1 Answer 1

3

Try about:config and setting dom.confirm_repost.testing.always_accept = true Helped me in Firefox 84

2
  • Can't confirm since I no longer work with that stack but that sounds promising! I'll accept the answer is someone else can confirm that it fixes the issue. Thanks!
    – Ariane
    Jan 6, 2021 at 17:57
  • Great, it worked for me! Do you know if an option exists to allow this only on some URLs? For instance, just for localhost
    – azmeuk
    Jul 28, 2021 at 9:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .