Can't set gadget preferences via javascript
Asked by Dmitrii Shiriaev:

Hello,

We encountered a regression in the javascript gadget API after upgrading our Confluence server from version 5 to 6.8.1. OpenSocial gadget javascript API method to set preferences (<https://developers.google.com/gadgets/docs/reference/#set>) stopped working. Confluence does not show any errors. Javascript error appears in the browser console. If someone has information about a known bug in Confluence 6.8.1, about the obsolescence of the OpenSocial JavaScript gadget API in Confluence or workarounds, please reply.

Atlassian support answered that this case is "beyond their [support scope](https://confluence.atlassian.com/display/Support/Atlassian+Support+Offerings)".

Steps to reproduce {#toc-hId-1818234907}
----------------------------------------

1. Deploy the following simple gadget at a web server:
   1.

      ```
      <?xml version="1.0" encoding="UTF-8"?>
      <Module>
      ??????? <ModulePrefs
      ??????????????? title="Bug test. Can't save gadgets preferences."
      ??????????????? description=""
      ??????????????? height="300px"
      ??????????????? author="Dmitrii Shiriaev and Plesk Team"
      ??????????????? author_email=""
      ??????????????? screenshot=""
      ??????????????? thumbnail=""
      ??????? >
      ??????????????? <Require feature="setprefs"/>
      ??????????????? <Optional feature="gadget-directory">
      ??????????????????????? <Param name="categories">Other</Param>
      ??????????????? </Optional>
      ??????? </ModulePrefs>

      ??????? <UserPref name="testPref" datatype="string" default="" />

      ??????? <Content type="html">
      ??????????????? <![CDATA[
      ??????????????????????? <script type="text/javascript">
      ??????????????????????????????? var prefs = new gadgets.Prefs();
      ??????????????????????? </script>
      ??????????????????????? <textarea id="textarea"></textarea>
      ??????????????????????? <button id="get" onclick="document.getElementById('textarea').value = prefs.getString('testPref')">Get</button>
      ??????????????????????? <button id="set" onclick="prefs.set('testPref', document.getElementById('textarea').value);">Set</button>
      ??????? ]]>
      ??????? </Content>
      </Module>
      ```

2. Add the gadget to Confluence at "External Gadgets"/"Add a new Gadget" using the gadget specification URL
3. Create a Confluence page
4. Insert the gadget
5. Publish the page
6. Type some text in the textarea of the gadget
7. Press Set button
   1. *The gadget will try to set 'testPref' preference with value of the textarea using method 'set' of 'gadgets.Prefs' object (see the source code of the gadget and OpenSocial gadget javascript API at <https://developers.google.com/gadgets/docs/reference/#set>)*
8. Open the browser console
   1. **Actual result:**
      1.

         ```
         17:38:51.333 Error: subclass responsibility batch.js:20:1472
         gadgets.GadgetService.prototype.setUserPref https://confluence.corp.com/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_US/7701/445126ab56584205167f1c035c86df495c7c4192/49062bdb4ed83e97670676342f1428be/_/download/contextbatch/js/render-gadget,-_super/batch.js:20:1472 
         gadgets.IfrGadgetService/< https://confluence.corp.com/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_US/7701/445126ab56584205167f1c035c86df495c7c4192/49062bdb4ed83e97670676342f1428be/_/download/contextbatch/js/render-gadget,-_super/batch.js:20:1737 
         process https://confluence.corp.com/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_US/7701/445126ab56584205167f1c035c86df495c7c4192/49062bdb4ed83e97670676342f1428be/_/download/contextbatch/js/render-gadget,-_super/batch.js:5:2657 
         receiveSameDomain/< https://confluence.corp.com/s/d41d8cd98f00b204e9800998ecf8427e-CDN/en_US/7701/445126ab56584205167f1c035c86df495c7c4192/49062bdb4ed83e97670676342f1428be/_/download/contextbatch/js/render-gadget,-_super/batch.js:5:7488 
         openRemotePrompt jar:file:///usr/lib/firefox/omni.ja!/components/nsPrompter.js:505:5 
         openPrompt jar:file:///usr/lib/firefox/omni.ja!/components/nsPrompter.js:539:17 
         alert jar:file:///usr/lib/firefox/omni.ja!/components/nsPrompter.js:612:9 
         kMa https://calendar.google.com/calendar/_/scs/calendar-static/_/js/k=calendar.mat.ru.kPhECKKsnIg.O/m=pjCC5c,KQU6nb,RWEy5c,sygk,NJddyf,syeu,UDuglb,sygb,syje,syjf,SUIuyf,CbhGKd,sy50,dSba8,sy53,sy54,sy52,sy55,sy56,sy58,sy4t,sy4v,sy57,sy59,lateload/am=ABAAgQI/rt=j/d=0/rs=ANwU0p6yo-9NtTI0gh59kpvQH3q5NBWGHg:191:467 
         nMa https://calendar.google.com/calendar/_/scs/calendar-static/_/js/k=calendar.mat.ru.kPhECKKsnIg.O/m=pjCC5c,KQU6nb,RWEy5c,sygk,NJddyf,syeu,UDuglb,sygb,syje,syjf,SUIuyf,CbhGKd,sy50,dSba8,sy53,sy54,sy52,sy55,sy56,sy58,sy4t,sy4v,sy57,sy59,lateload/am=ABAAgQI/rt=j/d=0/rs=ANwU0p6yo-9NtTI0gh59kpvQH3q5NBWGHg:190:129 
         mMa https://calendar.google.com/calendar/_/scs/calendar-static/_/js/k=calendar.mat.ru.kPhECKKsnIg.O/m=pjCC5c,KQU6nb,RWEy5c,sygk,NJddyf,syeu,UDuglb,sygb,syje,syjf,SUIuyf,CbhGKd,sy50,dSba8,sy53,sy54,sy52,sy55,sy56,sy58,sy4t,sy4v,sy57,sy59,lateload/am=ABAAgQI/rt=j/d=0/rs=ANwU0p6yo-9NtTI0gh59kpvQH3q5NBWGHg:192:142
         ```

   2. **Expected result:**
      1. No errors added to console on pressing Set button
9. Reload the page
10. Press Get button
    1. *The gadget will try to get the value of 'testPref' preference using method 'getString' of 'gadgets.Prefs' object (see the source code of the gadget and OpenSocial gadget javascript API <https://developers.google.com/gadgets/docs/reference/#getstring>)*
       1. **Actual result**
          1. The textarea has initial value of 'testPref' preference passed in gadget macro
       2. **Expected result**
          1. The textarea has the value was set by pressing the Set button

Confluence version {#toc-hId--733922054}
----------------------------------------

### Server 6.8.1 {#toc-hId-812374776}

Known browsers in which the issue is reproduced {#toc-hId--1543268680}
----------------------------------------------------------------------

* Mozilla firefox 60.0.1 (64-bit, Ubuntu 14.04)
* Chromium 65.0.3325.181 (64-bit, Ubuntu 14.04)

Atlassian support request {#toc-hId-199541655}
----------------------------------------------

Number: CSP-230100

Link: <https://getsupport.atlassian.com/servicedesk/customer/portal/14/CSP-230100>


Answers:
author: Michael Eskin
body: I am having exactly the same problem porting my Jira server gadgets to Confluence server, but it is failing the setPrefs exactly as you describe (subclass responsibility error) but on Confluence 5.1


Tags: gadget

api

confluence-server

javascript

server