question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a client API?

See original GitHub issue

First off, thanks for this project, I love it!

I don’t like a full refresh on each page change so I added barba.js in order to load the pages over AJAX instead. This obviously broke giscus, I hacked around a solution that involves changing the iframe src on page change via JS but I was wondering if there’s a better way to solve this.

I don’t know if that’s possible but will you consider adding a JS client API so that we can programmatically load the discussion?

You can see my tiny js code here and you can see it in action at https://games-on-whales.github.io/gow/

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ABeltramocommented, Jul 11, 2021

Thank you for your patience, it works perfectly! 🎉 I feel dumb to have missed that, I just tried to see thru the Typescript since I’m just on plain JS and I missed those keys!

1reaction
laymonagecommented, Jul 11, 2021

@ABeltramo Ah, I just realized: you need to wrap the object in this format:

frame.contentWindow.postMessage({
  giscus: {
    setConfig: {
      term: term,
      repo: "games-on-whales/gow",
    }
  }
}, 'https://giscus.app')

Sorry if it doesn’t seem so intuitive. The reason is:

  • The object is wrapped in the giscus key because other apps might also send messages to the window (e.g. browser extensions). The key ensures that the data is specifically intended for giscus.
  • The config is wrapped in the setConfig key because there may be other types of messages that will be supported by giscus in the future. I could’ve added a property like type: 'set-config' and just put the rest of the data without wrapping it in setConfig, but I chose the current approach because it lets you namespace the data for each type of message and still be able to check the type (using if ('setConfig' in giscus)).

This is why I added a boilerplate example in the guide:

function sendMessage<T>(message: T) {
  const iframe = document.querySelector<HTMLIFrameElement>('iframe.giscus-frame');
  if (!iframe) return;
  iframe.contentWindow.postMessage({ giscus: message }, 'https://giscus.app');
}

sendMessage({
  setConfig: {
    theme: 'https://giscus.app/themes/custom_example.css',
    reactionsEnabled: false,
  }
});

It seems to work on my website:

Peek 2021-07-11 16-12

(Sorry for the screen glitch, screen recording doesn’t seem to work well on my linux setup.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

AddClient - WHMCS Developer Documentation
WHMCS developer documentation - themes, modules, hooks, oauth, api and ... Adds a client. ... firstname, string, First name of the client to...
Read more >
How to create a Client for your API — .NET | by Tiago Martins
In my opinion, this is a simple and efficient way to create clients for APIs. The fact of having multiple controllers doesn't create...
Read more >
Add an API Client - Salesforce Commerce Cloud Infocenter
Log into Account Manager. · Click API Client. · Click Add API Client. · In the Display Name field, enter the display name...
Read more >
Adding a New Client | API | Zoho People
Adding new clients using API in Zoho People. ... This API is used to add client. ... *clientName, <Client name>, <Mandatory>, Specify the...
Read more >
Quickstart: Configure a client application to access a web API
Select Azure Active Directory > App registrations, and then select your client application (not your web API). Select API permissions > Add ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found