0
votes

So i have created a custom dynamic action that is supposed to run "beforeunload" (in case user closes the tab/browser unexpectedly or navigates away from the page in a manner not intended). This dynamic action runs a simple plsql procedure ( http://prntscr.com/qz0a6c ). A few days ago the Chrome browser updated to version 80 and in this new version "beforeunload" is disallowed and now my dynamic action does not work.

Does anyone have an idea on how I could build this functionality differently? Apex 4.2 is in question.

2
Yes i have...but I don't know how to implement this in apexDejan Dragicevic
I could probably show you how, but first, please tell me a bit about what the PL/SQL code and the JavaScript code in the actions are doing (I'll need to be sure you can still do it). Also, do you have the ability to create REST APIs in the SQL Workshop?Dan McGhan
Nevermind... I think I have something generic enough for you that doesn't require ORDS. I'll post an answer soon.Dan McGhan

2 Answers

0
votes

I guess you are hitting Disallow sync XHR in page dismissal So to turn your DA to asynchronous one try to set Wait for result property of your dynamic actions to false.

0
votes

Here's a complete answer that you should be able to adapt to your situation.

  1. Create a new table to record send beacon data.

    create table beacons (
      id        number generated always as identity primary key,
      app_user  varchar2(255),
      date_sent date,
      data      varchar2(4000)
    );
    

    I used a varchar2 for the data but that could be a CLOB if needed. I'll be passing the data in using the p_clob_01 parameter for Ajax.

  2. Create an Application Process named RECEIVE_BEACON in the Shared Components. Use the following code for the PL/SQL code:

    insert into beacons (
      app_user,
      date_sent,
      data
    ) values (
      :APP_USER,
      sysdate,
      apex_application.g_clob_01
    );
    
  3. Create a Dynamic Action named Window beforeunload. Set Event to Custom, Custom Event to beforeunload, Selection Type to JavaScript Expression, and JavaScript Expression to window.

    enter image description here

  4. Select the Action for the Dynamic Action created in step 3. Set the Action to Execute JavaScript Code. Copy/paste the following into the Code field.

    var beaconData = {
      test: 'value'
    };
    
    var formData = new FormData();
    
    formData.append('p_flow_id', '&APP_ID.');
    formData.append('p_flow_step_id', '&APP_PAGE_ID.');
    formData.append('p_instance', '&APP_SESSION.');
    formData.append('p_debug', '');
    formData.append('p_request', 'APPLICATION_PROCESS=RECEIVE_BEACON');
    formData.append('p_clob_01', JSON.stringify(beaconData));
    
    navigator.sendBeacon('/pls/apex/wwv_flow.ajax', formData);
    

Save your changes and run the page. Then refresh the page to trigger the Dynamic Action and send the beacon. This example shows how you can send random data from JavaScript but also get session-related data, such as the user name.