title: Browser back action does not work in Firefox when PayPal Plus iframe is rendered in page of react app
body: <p>I integrated the PayPal Plus iframe into my react app by appending the PayPal library js-script to the document in componentDidMount, updating the component state when the script is loaded and then calling the library method to initialize the PayPal Plus object. This renders the iframe into the placeholder div with the according id. I consulted the documentation (<a href="https://developer.paypal.com/docs/paypal-plus/germany/integrate/integrate-payment-wall/#" rel="nofollow noreferrer">https://developer.paypal.com/docs/paypal-plus/germany/integrate/integrate-payment-wall/#</a>) and did the aforementioned adaptations to use it in combination with my react app.</p>
  <p>This works so far and looks like this in the minimalized example: <a href="https://i.stack.imgur.com/4fi7q.png" rel="nofollow noreferrer">page with rendered ppp iframe</a></p>
  <p>In Firefox though, it isn't possible to navigate back by the browser's back button, once the iframe has been initialized.
  Instead, the whole component is loaded inside of the iframe. Like this: <a href="https://i.stack.imgur.com/N4rjq.png" rel="nofollow noreferrer">page after clicking back button</a></p>
  <p>This doesn't happen in Chrome or Internet Explorer.
  Firefox version: 81.0 (64-Bit)</p>
  <p>If I manually delete the iframe element from the DOM, the back button works normally again.
  I already tried using custom event handlers for the &quot;popstate&quot; and &quot;beforeunload&quot; events, to try to work around this but to no avail. Those events seemingly don't occur in the parent window in Firefox.</p>
  <p>Steps to reproduce:</p>
  <ul>
  <li>Create react app (i used V16.13.1 in the example) (<a href="https://reactjs.org/docs/create-a-new-react-app.html#create-react-app" rel="nofollow noreferrer">https://reactjs.org/docs/create-a-new-react-app.html#create-react-app</a>).</li>
  <li>Insert provided classes into the project and use PppComponent in App.js.</li>
  <li>Acquire valid PayPal sandbox approvalUrl and set it on ppp config object.</li>
  <li>Run yarn or npm start.</li>
  <li>Open the app in Mozilla Firefox and click the back button of the browser.</li>
  </ul>
  <p>This is basically the related code of the component:</p>
  <pre><code>import React from 'react';
  import utils from './utils';
  
  class PppComponent extends React.Component {
      constructor() {
          super();
          this.state = {
              scriptLoaded: false
          }
      }
  
      componentDidMount() {
          utils.appendScript(
              'https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js',
              () =&gt; this.setState({scriptLoaded: true})
          );
      }
  
      componentWillUpdate(nextProps, nextState) {
          if (nextState.scriptLoaded) {
              this.initPaypalPlusIframe();
          }
      }
  
      componentWillUnmount() {
          utils.removeScript('https://www.paypalobjects.com/webstatic/ppplus/ppplus.min.js');
      }
  
      initPaypalPlusIframe() {
          const pppConfig = {
              approvalUrl: '{validApprovalUrl}',
              placeholder: 'ppplus',
              mode: 'sandbox',
              language: 'de_DE',
              country: 'DE',
              useraction: 'commit',
          };
          window.PAYPAL.apps.PPP(pppConfig);
      }
  
      render() {
          return (
              &lt;div&gt;
                  &lt;h1&gt;Some Content Here&lt;/h1&gt;
                  &lt;div id=&quot;ppplus&quot;/&gt;
              &lt;/div&gt;
          );
      }
  }
  
  export default PppComponent;
  </code></pre>
  <p>And these are the util functions, used to append and remove the script:</p>
  <pre><code>    class Utils {
  
      appendScript(scriptToAppend, onLoad) {
          const allSuspects = document.getElementsByTagName('script');
          let doAppend = true;
          if (allSuspects &amp;&amp; allSuspects.length &gt; 0) {
              for (let i = allSuspects.length - 1; i &gt;= 0; i--) {
                  if (allSuspects[i] &amp;&amp; allSuspects[i].getAttribute('src') !== null
                      &amp;&amp; allSuspects[i].getAttribute('src').indexOf(`${scriptToAppend}`) !== -1) {
                      doAppend = false;
                  }
              }
          }
      
          if (doAppend) {
              const script = document.createElement('script');
              script.src = scriptToAppend;
              script.async = false;
              script.onload = () =&gt; onLoad();
              document.body.appendChild(script);
          }
      }
  
      removeScript(scriptToRemove) {
          const allSuspects = document.getElementsByTagName('script');
          for (let i = allSuspects.length - 1; i &gt;= 0; i--) {
              if (allSuspects[i] &amp;&amp; allSuspects[i].getAttribute('src') !== null
                  &amp;&amp; allSuspects[i].getAttribute('src').indexOf(`${scriptToRemove}`) !== -1) {
                  allSuspects[i].parentNode.removeChild(allSuspects[i]);
              }
          }
      }
  }
  
  export default new Utils();
  </code></pre>
  <p>Has anybody an idea why this happens or maybe experienced something similar and knows how to fix/workaround this behavior?</p>
  <p>I'd be glad about any help.</p>
  <p>Thank You in advance.</p>