IBM Cognos TM1 Web Clipboard Extension and a bit more

Post Reply
konstantin-spb
Posts: 18
Joined: Thu Feb 20, 2014 8:42 am
OLAP Product: TM1
Version: PA 2.0.9
Excel Version: 2016
Location: Russia, Saint-Petersburg

IBM Cognos TM1 Web Clipboard Extension and a bit more

Post by konstantin-spb »

Good afternoon.
  • 1. The problem of copying (tm1webCopy) from TM1Web to external sources and pasting (tm1webPaste) from external sources into TM1Web (for versions before 2.0.88, in which IBM added built-in clipboard support) via an extension:
    • 1.1. Because Google Chrome switched to Manifest V3 long ago, the "official" IBM Cognos TM1 Web Clipboard Extension (version 1.0.0.4 Manifest V2) was removed from the app store. It no longer works even when installed in developer mode.
    • 1.2. Until the end of 2026, Manifest V2 will be supported in Microsoft Edge. It cannot be installed from the app store (it has been removed), but it can still be installed in developer mode.

    On github there is a solution to this problem (thanks to Gleb Karpushkin) — a rewritten extension for Manifest V3 that can be installed in developer mode in Chromium-based browsers (Google Chrome, Microsoft Edge): https://github.com/Luccifer/IBM-Cognos- ... -Extension

    I have tested it, and it works perfectly!

  • 2. Since I did not have access to 2.0.88 and no ability to upgrade to that version, and did not want to use the extension, I tried to write scripts in order to embed clipboard support into earlier versions TM1Web (for example, 2.0.9):

    The result was a single ClipboardService.js, which is included in application.jsp (with minimal code added).

    It is important that ClipboardService.js be included in application.jsp before TM1WebApp.js (or TM1WebAppCam.js) and before the domReady! callback fires:

    ClipboardService.js:

    Code: Select all

    /**
     * Central clipboard service for TM1 Web.
     * Replaces the browser extension by handling tm1webPaste / tm1webCopy events.
     */
    (function (global) {
        'use strict';
    
        var ClipboardService = {
    		
            initialized: false,
    
            init: function () {
                if (this.initialized) { return; }
    
                var root = document.documentElement;
                if (!root) {
                    console.error('[TM1 Clipboard] document.documentElement is not available.');
                    return;
                }
    
                root.addEventListener('tm1webPaste', this._onPaste.bind(this), false);
                root.addEventListener('tm1webCopy', this._onCopy.bind(this), false);
    
                if (!navigator.clipboard ||
                    typeof navigator.clipboard.readText !== 'function' ||
                    typeof navigator.clipboard.writeText !== 'function') {
                    console.error('[TM1 Clipboard] Clipboard API not available. HTTPS required.');
                }
    
                this.initialized = true;
            },
    
            _onPaste: async function (evt) {
                evt.preventDefault();
                var root = document.documentElement;
                var responseEventName = 'tm1webPasteResponse' + evt.timeStamp;
    
                try {
                    var text = await navigator.clipboard.readText();
                    root.dispatchEvent(new CustomEvent(responseEventName, {
                        bubbles: false,
                        cancelable: true,
                        detail: { value: text, success: true }
                    }));
                } catch (err) {
                    console.error('[TM1 Clipboard] Paste failed:', err);
                    root.dispatchEvent(new CustomEvent(responseEventName, {
                        bubbles: false,
                        cancelable: true,
                        detail: { value: null, success: false, error: err && err.message }
                    }));
                }
            },
    
            _onCopy: async function (evt) {
                evt.preventDefault();
                if (!evt.detail || evt.detail.value == null) { return; }
    
                var root = document.documentElement;
    
                try {
                    await navigator.clipboard.writeText(evt.detail.value);
                    if (evt.detail.callback) {
                        root.dispatchEvent(new CustomEvent('tm1webCopyResponse', {
                            bubbles: false,
                            cancelable: true,
                            detail: { success: true }
                        }));
                    }
                } catch (err) {
                    console.error('[TM1 Clipboard] Copy failed:', err);
                    if (evt.detail.callback) {
                        root.dispatchEvent(new CustomEvent('tm1webCopyResponse', {
                            bubbles: false,
                            cancelable: true,
                            detail: { success: false, error: err && err.message }
                        }));
                    }
                }
            }
        };
    
        global.TM1ClipboardService = ClipboardService;
    })(window);
    application.jsp:

    Code: Select all

    ...
        <script src="scripts/dojo/dojo.js" data-dojo-config="locale:'<%=getLocale(request)%>'"></script>
        <script src="scripts/tm1web/share/ClipboardService.js"></script>
        <script>
           require(["tm1web/standalone/TM1WebAppCam"], function(TM1WebAppCam) {
                TM1WebAppCam.host = "<%= host %>";
                TM1WebAppCam.serverName = "<%= server %>";
                TM1WebAppCam.c_pp = "<%= c_pp %>";
                TM1WebAppCam.c_ss = "<%= c_ss %>";
           });
        </script>
        <script>
           require(["dojo/domReady!"], function () {
                if (window.TM1ClipboardService) window.TM1ClipboardService.init();
           });
        </script>
    ...	


! Please note that modern browsers require HTTPS* (or localhost) for the Clipboard API to work, and they also often request permission from the user on first access.

HTTPS* is simple: use Traefik, Caddy, HAProxy or Nginx in front of Planning Analytics (TM1Web).
Post Reply