diff --git a/web/pgadmin/browser/static/js/browser.js b/web/pgadmin/browser/static/js/browser.js
index 3ba7a318..4ce94b8c 100644
--- a/web/pgadmin/browser/static/js/browser.js
+++ b/web/pgadmin/browser/static/js/browser.js
@@ -1945,12 +1945,17 @@ define('pgadmin.browser', [
   }
 
   $(window).on('beforeunload', function(e) {
+    /* Can open you in new tab */
+    let openerBrowser = window.opener ?
+      window.opener.pgAdmin.Browser : window.top.pgAdmin.Browser;
+
     let tree_save_interval = pgBrowser.get_preference('browser', 'browser_tree_state_save_interval'),
-      confirm_on_refresh_close = pgBrowser.get_preference('browser', 'confirm_on_refresh_close');
+      confirm_on_refresh_close = openerBrowser.get_preference('browser', 'confirm_on_refresh_close');
+
     if (!_.isUndefined(tree_save_interval) && tree_save_interval.value !== -1)
       pgAdmin.Browser.browserTreeState.save_state();
 
-    if(confirm_on_refresh_close.value) {
+    if(!_.isUndefined(confirm_on_refresh_close)) {
       /* This message will not be displayed in Chrome, Firefox, Safari as they have disabled it*/
       let msg = S(gettext('Are you sure you want to close the %s browser?')).sprintf(pgBrowser.utils.app_name).value();
       e.originalEvent.returnValue = msg;
diff --git a/web/pgadmin/tools/datagrid/__init__.py b/web/pgadmin/tools/datagrid/__init__.py
index 05e723ea..c0f61e9f 100644
--- a/web/pgadmin/tools/datagrid/__init__.py
+++ b/web/pgadmin/tools/datagrid/__init__.py
@@ -411,7 +411,7 @@ def initialize_query_tool(sgid, sid, did=None):
     )
 
 
-@blueprint.route('/close/<int:trans_id>', methods=["GET"], endpoint='close')
+@blueprint.route('/close/<int:trans_id>', methods=["DELETE"], endpoint='close')
 def close(trans_id):
     """
     This method is used to close the asynchronous connection
diff --git a/web/pgadmin/tools/datagrid/static/js/datagrid.js b/web/pgadmin/tools/datagrid/static/js/datagrid.js
index b22034e0..3e2e1440 100644
--- a/web/pgadmin/tools/datagrid/static/js/datagrid.js
+++ b/web/pgadmin/tools/datagrid/static/js/datagrid.js
@@ -505,7 +505,7 @@ define('pgadmin.datagrid', [
           queryToolPanel.on(wcDocker.EVENT.CLOSED, function() {
             $.ajax({
               url: url_for('datagrid.close', {'trans_id': trans_obj.gridTransId}),
-              method: 'GET',
+              method: 'DELETE',
             });
           });
 
diff --git a/web/pgadmin/tools/datagrid/templates/datagrid/index.html b/web/pgadmin/tools/datagrid/templates/datagrid/index.html
index 59460831..f138b9a4 100644
--- a/web/pgadmin/tools/datagrid/templates/datagrid/index.html
+++ b/web/pgadmin/tools/datagrid/templates/datagrid/index.html
@@ -368,12 +368,24 @@
         msgDiv = loadingDiv.find('.sql-editor-busy-text');
 
     // Register unload event on window close.
-    window.onbeforeunload = function(ev) {
-      $.ajax({
-        url: "{{ url_for('datagrid.index') }}" + "close/" + {{ uniqueId }},
-        method: 'GET'
+    /* If opened in new tab, close the connection only on tab/window close and
+     * not on refresh attempt because the user may cancel the reload
+     */
+    if(window.opener) {
+      $(window).on('unload', function(ev) {
+        $.ajax({
+          method: 'DELETE',
+          url: "{{ url_for('datagrid.index') }}" + "close/" + {{ uniqueId }}
+        });
       });
-    };
+    } else {
+      $(window).on('beforeunload', function(ev) {
+        $.ajax({
+          method: 'DELETE',
+          url: "{{ url_for('datagrid.index') }}" + "close/" + {{ uniqueId }}
+        });
+      });
+    }
 
     // Get the controller object from pgAdmin.SqlEditor
     var sqlEditorController = pgAdmin.SqlEditor.create(editorPanel);
diff --git a/web/pgadmin/tools/debugger/static/js/debugger.js b/web/pgadmin/tools/debugger/static/js/debugger.js
index ed0f6b79..2ee1d55c 100644
--- a/web/pgadmin/tools/debugger/static/js/debugger.js
+++ b/web/pgadmin/tools/debugger/static/js/debugger.js
@@ -196,14 +196,14 @@ define([
 
       let self = this;
       let cacheIntervalId = setInterval(function() {
-        try {
-          self.preferences = window.top.pgAdmin.Browser;
+        if(pgBrowser.preference_version() > 0) {
+          self.preferences = pgBrowser.get_preferences_for_module('debugger');
           clearInterval(cacheIntervalId);
         }
-        catch(err) {
-          clearInterval(cacheIntervalId);
-          throw err;
-        }
+      },0);
+
+      pgBrowser.onPreferencesChange('debugger', function() {
+        self.preferences = pgBrowser.get_preferences_for_module('debugger');
       });
     },
     // It will check weather the function is actually debuggable or not with pre-required condition.
diff --git a/web/pgadmin/tools/debugger/templates/debugger/direct.html b/web/pgadmin/tools/debugger/templates/debugger/direct.html
index d5a97138..f4965c4f 100644
--- a/web/pgadmin/tools/debugger/templates/debugger/direct.html
+++ b/web/pgadmin/tools/debugger/templates/debugger/direct.html
@@ -10,12 +10,26 @@ try {
       var $ = pgDirectDebug.jquery;
 
       pgDirectDebug.load({{ uniqueId }}, {{ debug_type }}, '{{ function_name_with_arguments }}', '{{layout|safe}}');
-      window.onbeforeunload = function(ev) {
-        $.ajax({
-          url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}",
-          method: 'DELETE'
+
+      // Register unload event on window close.
+      /* If opened in new tab, close the connection only on tab/window close and
+       * not on refresh attempt because the user may cancel the reload
+       */
+      if(window.opener) {
+        $(window).on('unload', function(ev) {
+          $.ajax({
+            method: 'DELETE',
+            url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}"
+          });
+        });
+      } else {
+        $(window).on('beforeunload', function(ev) {
+          $.ajax({
+            method: 'DELETE',
+            url: "{{ url_for('debugger.index') }}close/{{ uniqueId }}"
+          });
         });
-      };
+      }
     },
     function() {
       console.log(arguments);
