How to test OAuth2 login flow in Chrome extension?

I’m new to web development and working on a Chrome extension which links up to your Google account using OAuth2. I’m using the following code to get an auth token for the current user:

    chrome.identity.getAuthToken({ interactive: true }, function (token) {
      // do some stuff
    });

when I ran this code, it brought me to a login screen where I was able to log in with my Google account. Now when I call this, I get a valid token.

However, now I want to test the login flow as if I was a user logging in for the first time. From the Chrome docs, I tried running:

chrome.identity.clearAllCachedAuthTokens();

But that didn’t seem to make a difference. I also tried running:

chrome.identity.getAuthToken({ interactive: true }, function (token) {
    chrome.identity.removeCachedAuthToken({ token: token }, function (){})

And that didn’t work either. I also opened the extension in incognito mode but was still able to get the auth token instead of a login screen.

How can I “unauthenticate” or “log out” so that I can go through the auth flow again?

json-rpc 2.0 API sever. Modifying Basic Auth to use sha256 instead of base64. Is it naïve?

I’ve put together a json-rpc 2.0 server to better understand the protocol. I’ve finally got to the part where I start to consider securing it and went on to learn about Basic Auth.

In the standard Basic Auth you see the following workflow:

A POST request is made to /jsonrpc including the HTTP Header Authorization: Basic dXNlcjE6bGV0bWVpbg==

This header value is equal to user1:letmein encoded to base64

> POST /jsonrpc HTTP/1.1
> Host: 10.10.1.100:3000
> User-Agent: insomnia/2022.7.5
> Content-Type: application/json
> Authorization: Basic dXNlcjE6bGV0bWVpbg==
> Accept: */*
> Content-Length: 0

Response is received in JSON format including token to be use for subsequent requests.

< HTTP/1.1 200 OK
< access-control-allow-methods: POST
< access-control-allow-origin: *
< allow: POST
< cache-control: no-store
< content-language: en-US
< content-type: application/json; charset=UTF-8
< server: JSON-RPC 2.0 Server
< vary: Accept-Encoding
< content-length: 143
< date: Mon, 06 Mar 2023 21:28:18 GMT
{
  "jsonrpc": "2.0",
  "method": "auth",
  "result": {
    "token": "3c469e9d6c5875d37a43f353d4f88e61fcf812c66eee3457465a40b0da4153e0",
    "expires": 1678141698081
  }
}

My question is, obviously, base64 might as well be plain text sent over the network so it’s not secure.

Would replacing base64 encoding with sha256 from Web Crypto API SubtleCrypto.digest() method make this more secure or is it just the same and naïve.

const encoder = new TextEncoder();

async function sha256(message: string): Promise<string> {
  // encode as (utf-8) Uint8Array
  const msgUint8: Uint8Array = encoder.encode(message);
  // hash the message
  const hashBuffer: ArrayBuffer = await crypto.subtle.digest("SHA-256", msgUint8);
  // convert buffer to byte array
  const hashArray: number[] = Array.from(new Uint8Array(hashBuffer));
  // convert bytes to hex string
  const hashHex: string = hashArray.map(b => b.toString(16).padStart(2, "0")).join("");
  // return hex string
  return hashHex;
}

Javascript closure returning object that modifies array weird behavior

Im trying to understand what’s going on here with the behavior of this function:

function closure2() {
    const arr = [];
    arr.forEach(a => { console.log('ARR ELEMENT: ', a) })
    return {
        onDataReady: (arrElement) => arr.push(arrElement)
    }
}

I use the code like this:

const c = closure2()
// now, call ondataready with elements to populate arr
c.onDataReady('test1') // expect arr.forEach to print 'ARR ELEMENT: test1'
// actual output:  1
// the following is calls to onDataReady with output
c.onDataReady('test2')
2
c.onDataReady('test3')
3
c.onDataReady('test3')
4
c.onDataReady('test3')
5

What am I doing wrong here to not get ‘ARR ELEMENT: test1/test2/etc.’ to print??
Is there some hidden rule in closures that i am missing?

How to make dropdown menu button also a button for a link?

This is my html code and I cant figure out how to get the button to be a link. Despite adding the anchor tag with a link inside, when I click on the button, nothing happens.

Week 8 Homepage

Ron’s Clothes

      <span>
        <div class="dropdown link1">
          <a href="link1.html" style="text-decoration: none;">
            <button class="btn btn-secondary btn-clr dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
              Shop
            </button>
          </a>
          <ul class="dropdown-menu">
            <li><a class="dropdown-item" href="link1.html">Tops</a></li>
            <li><a class="dropdown-item" href="link1.html">Pants</a></li>
            <li><a class="dropdown-item" href="link1.html">Outerwear</a></li>
          </ul>
          <a href="link1.html" style="text-decoration: none;"></a>
        </div>
      </span>

    </div>

    <img class="image" src="Screenshot (27).png" alt="clothes image">

    <h1 class="featured">Featured Items</h1>

    <div class="featuredimg">
        <div class="column position1">
          <a href="link1.html" style="text-decoration: none;">
            <img src="shirt1.jpeg" alt="featured1" style="width: 75%">
            <p>Early 90s Brine for Major Soccer<br>League Tee<br><strong>$38.58</strong></p>
          </a>
        </div>
        <div class="column position2">
          <img src="shirt2.jpeg" alt="featured2" style="width: 75%">
          <p>90s Nike 'There Is No Finish Line'<br>Windbreaker<br><strong>$75.32</strong></p>
        </div>
        <div class="column position3">
          <img src="shirt3.jpeg" alt="featured3" style="width: 75%">
          <p>1992/1993 Manchester United F.C.<br>Training Tee<br><strong>$68.64</strong></p>
        </div>
        <div class="column position4">
          <img src="shirt4.jpeg" alt="featured4" style="width: 75%">
          <p>1995 Houston Rockets x Looney Tunes<br>'Daffy Duck' Tee<br><strong>$43.93</strong></p>
        </div>
      </div>
</body>

I tried shifting the anchor tag around and it doesn’t work, sometimes the dropdown menu stops working too. I tried using javascript, giving the button and id and adding event listener but that doesn’t work either. I need some help on this as I’m out of ideas.

Exaggerate the size of a series if it is very small compared to another HighCharts

I need to compare two values in a chart, the problem is that one of the series has lower values and it looks too small, is there a way to “exaggerate” the size so they don’t get lost? Before I had two axes but I was asked to have only one axis.

An example of the data I have (The information carried by spline grows much more as the information advances compared to the column bar data). I tried putting a minimum point but I feel that the most important point is lost, which is to compare how much has grown between one data and the other

This is what I have
https://jsfiddle.net/bqoenayj/22/

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>

<div id="container"></div>
Highcharts.chart('container', {

    xAxis: {
        categories: ['E', 'F', 'M']
    },
    yAxis: {
      title: { text: '' },
    },
    plotOptions: {
        series: {
            //minPointLength: 50
        }
    },
    series: [{
        type: 'column',
        name: 'DATA 1',
        color: '#FFDC82',
        data: [339.61, 440.42, 682.03]
    },{
        type: 'spline',
        name: 'DATA 2',
        color: '#7678AD',
        data: [4117, 4913.33, 13133],
        marker: {
            lineWidth: 2,
            lineColor: Highcharts.getOptions().colors[3],
            fillColor: 'white'
        }
    }]
});

Hedera – Hethers.js interaction with smart contracts

I’m just learning the tools on heders.

Can we use only hethers.js to interact with smart contracts and what is the best way to read state from the hedera hashgraph?

I had read that also read functions are chargeable? Is this correct?

It isn’t clear to me the distinction between using the hederak sdk and tools like hethers.js.

How to implement SCORM player with react native?

Is there a way to create a simple SCORM player to load all the SCORM content that can play and track the progress. I have tried using HTMl and javascript, but that does not work as per expectations. Neither so I found any complete example for the available libraries.

So is there a way to do that ?

How to load items (images) in different order every time the page reloads/opens?

Lets say I have 2 sections with images. How to load different images in different order every time the page reloads or opens for first time?

I want to use Vanilla JavaScript for it.

Heres part of my code:

.article2Container{
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  top: 100px;
}

#sectionContainer{
  position: relative;
  height: 350px;
  width: 650px;
  background-color: rgb(30, 30, 30);
  border-top: 5px solid rgb(227, 0, 26);
  margin-bottom: 50px;
}

#sectionContainer2{
  position: relative;
  height: 350px;
  width: 350px;
  background-color: rgb(27, 27, 27);
  border-top: 5px solid rgb(227, 0, 26);
  margin-bottom: 50px;
}

.article2Title{
  position: absolute;
  left: 25px;
  top: -50px;
  font-family: myFont;
  color: rgb(227, 0, 26);
}

#academy{
  position: absolute;
  width: 50%;
  height: 100%;
}

.article2Text{
  position: absolute;
  display: block;
  font-family: myFont;
  width: 50%;
  color: white;
  margin: 20px 50px 20px 50px;
  left: 50%;
}

#textArtists, #dateText, #fbEvent{
  color: rgb(227, 0, 26);
  font-size: 13px;
}

.ticketsContainer{
  width: 80px;
  height: 40px;
  background-color: rgb(227, 0, 26);
  border-radius: 0 0 45px 0;
  text-align: center;
  cursor: pointer;
  font-family: myFont;
}

.ticketsContainer::before{
  content: "";
  position: absolute;
  width: 0%;
  height: 40px;
  background-color: white;
  left: 0;
  border-radius: 0 0 45px 0;
  transition: width 0.4s;
}

.ticketsContainer:hover::before{
  width: 80px;

}

.ticketsContainer p{
  position: relative;
  text-decoration: none;
  text-align: center;
  color: white;
  margin: auto;
  top: 45%;
  z-index: 99;
  line-height: 0;
  left: -1px;
  font-size: 13px;
  font-family: myFont;
}
            <article>
                <div class="article2Container">

                        <div id="sectionContainer">

                            <div class="article2Title">
                                <p>СЪБИТИЯ</p>
                            </div>

                            <a href="https://www.facebook.com/events/755319146289491" target="_blank">
                                <img id="academy" src="https://passionforedm.com/wp-content/uploads/2019/06/A-DJ-is-mixing-tracks-on-a-DJ-controller.jpg" alt="">
                            </a>

                            <div class="article2Text">
                                <p>Metropolis DJ Academy II 
                                   <br>
                                    April 2023
                                </p>

                                <p id="textArtists">
                                    Артисти
                                </p>
                                <p>
                                    DJ Smurf, DJ Steven, Jasen
                                    <br>
                                    Petrov
                                </p>
                                <p id="dateText">
                                    Дата и място
                                </p>
                                <p>
                                    03.04.2023, Понеделник
                                    <br>
                                    <span>Топлоцентрала</span>
                                </p>
                                <p id="fbEvent">
                                    Виж събитието във Facebook
                                </p>
                                <div class="ticketsContainer"
                                onclick="fbEvent()" 
                                onmouseenter="addAnimationButton(0, '.ticketsContainer')" 
                                onmouseleave="removeAnimation2(event)"
                                >
                                    <p class="seeMore" >БИЛЕТИ</p>
                                    <p class="seeMore" >БИЛЕТИ</p>
                                    <p class="seeMore" >БИЛЕТИ</p>
                                </div>
                            </div>
                        </div>


                        <div id="sectionContainer2">

                            <div class="article2Title">
                                <p>ПОДКАСТ</p>
                            </div>
                        </div>
        
        
                </div>
            </article>

Can i store img urls in array of objects or…? And how to display them every time in different order?

Why aren’t these buttons interactive?

To preface, I am a very new newbie to JS, so I might be missing something very obvious, but I’ve combed over the entire code at least twice, and I don’t see anything that would make it an issue. VS Code runs it without any error, but when I try to click the buttons in the actual webpage, the count doesn’t change with no console.log commands either. The program is meant to be a counter with three buttons that either increase decrease or reset the “Count”.

https://imgur.com/CFNoAF5
https://imgur.com/UvuzTlS

these are the JS file and the HTML file

Chrome headless won’t render JavaScript content to a text file from the Windows command line

I want chrome headless to return JavaScript-base content into the text file, out.txt. The Windows command-line below works fine for most URLs, but for the URL given below, out.txt is created successfully but empty. Why is this particular URL a problem, and how do I fix that?

windows> "C:Program Files (x86)GoogleChromeApplicationchrome.exe" --headless --disable-gpu --dump-dom --enable-logging https://digital.fidelity.com/prgw/digital/research/quote/dashboard/summary?symbol=IBM > out.txt
  • I tried removing the --headless flag, but that didn’t help.

  • I tried
    adding & timeout 3 to the end of the command line, but that didn’t
    help.

Could it be that the Chrome process exits before all the JavaScript is rendered? If so, how can I fix that easily on the command line?

Why is string interpolation not working in React Native?

I want to dynamically choose a weather icon based on the conditions using string interpolation. For some reason this is not working in React Native. Please tell me what I am missing. I have done the exact same thing with React so I don’t understand why it isn’t working in native.

If I do this for a specific image it works…

  setIcon(require(`./Icons/day/113.png`))

When I try and get the image dynamically it is not working…(pic gets the name of the image from the api)

  const pic = response.data.current.condition.icon.slice(-7);
  setIcon(require(`./Icons/day/${pic}`))

Then I am rendering the image like this….

      <View>
    <Image
      source={icon}
    />
    </View>