With Apex 5.1 we got a nifty new feature. It is now possible to clone an apex session, so that we can have two (or more) independent APEX sessions running in the same browser.
It only took me 2h to implement this from scratch. So it is really easy to do.
Joel Kallmann describes how to do it in this blog post http://joelkallman.blogspot.de/2016/07/apex-session-isolation-across-multiple.html
There are a few additional tweaks I would like to mention here.
Step 1) Enable session cloning on instance level
logon as sys (or any user with apex_administrator_role).
I first granted my normal DBA account the apex_administrator_role
grant apex_administrator_role to myDBA;
and then as DBA:
begin apex_instance_admin.set_parameter( p_parameter => 'CLONE_SESSION_ENABLED', p_value => 'Y'); end; /
If you are in a CDB/PDB environment, with Apex installed in the PDB (recommended) then make sure to run this on the matching PDB (especially when working with sys).
alter session set container = PDBAPEX
Joels article also explains how to enable this for a single workspace. But I got an error message when trying to do so.
"ORA-20987: APEX - Instance parameter not found - Contact your application administrator."
Step 2) Add a new navigation bar entry
Of cause you are free to add this functionality everywhere you want. But you will need a link, that the user has to click on to get a new session. My preference was the navigation bar.
The url for the link is simple. Just add APEX_CLONE_SESSION as the request parameter.
create a navigation bar list entry with this link
- Go to “Shared Components/Navigation Bar Lists/navigation bar” (the name of my list).
- Choose any icon (fa-clone) and label text (“Session klonen”) that you want.
- The target page needs to be “&APP_PAGE_ID.”. This will use the current page and add it into the link.
- And most importantly the request needs to be APEX_CLONE_SESSION.
The entry is now ready and working. However it will replace the session in the current browser tab. But rightclick and “open in new tab” gives us two tabs with a different apex session.
If that is not enough then this next step is wanted too.
Step 3) Open the link in a new page
The goal is to add a TARGET attribute to our link, so that a new tab is always opened when we clone the session. Unfortunatly the navbar template has no option to include link atributes. We could do a kind of injection trick with the url, but I prefere a cleaner way.
To do so we need to modify three small parts.
First copy the navigation bar template as a new template “Navbar with Attributes”
And there we add the user defined property #A03# to our link. This needs to be done in all areas where we find an <a..> tag.At least for the “list template current” and “list template non-current”. I also added it for the sub list entries, even if my navbar doesn’t use sub lists.
Don’t forget to add a description “Link Attributes” for the newly added attribute value in the “attribute description” section (scroll down a bit to see it).
Then enhance our existing navbar entry with target=”_blank”
There is a tiny difference between using target=”_blank” or target=someothername.
target=”_blank” will always create a new tab.
target=”_someothername” will open a new tab on the first click. Consecutive clicks however will always reuse this same tab. This can be useful if you want to prevent your users to constantly cloning session after session after session.
And finally make sure that our application uses the new template for showing the navbar list
Shared Components/User Interface Attributes/Desktop/Navigation bar/List Template
The navigation bar then could look similar to this here:
Clicking on the “clone session” link will open a new tab in the same browser. In the url we will see that a different session id was created.
The new session will have all the same item values (page items, application items, etc.) as the privious session had. But from this point on, the two sessions will start to differ.
Both sessions will use the same browser cookie. For that reason if one session logs out, then the other session will be logged out too.
7 thoughts on “Apex 5.1 session cloning”
Great blog posting! Thx for sharing this.
Thanks for the blog, very helpful!
For opening in a new windows I use target URL with the URL:
Thanks Peter for sharing this tipp. This is certainly also a good possibility and avoids creating a new template.
I found this little trick to reuse the same other tab:
I am doing the above steps and can see the target=”_test1” or target=”_test2” (shown below) when viewing the source of the html but for some reason it is not opening the page in a new tab. can you help please?
Strange. What browser do you use? You can try target=_blank first. Maybe the named version does work differently in your environment, but I’m not aware of such a behaviour. Try to test on https://www.w3schools.com/tags/att_a_target.asp and see what happens there.
[…] Apex 5 session cloning 2017.02 […]