This example uses OpenLayers v10.9.0. The latest is v.
Edit

#### WMS GetFeatureInfo (local MS4W layer)

mapserver 6 wms 14

#####

Using an image WMS source with GetFeatureInfo requests

This example shows how to trigger WMS GetFeatureInfo requests on click for a MapServer WMS layer. The local mapfile used is `/ms4w/apps/openlayers/en/latest/examples/map/wms-server.map` (data is in Spatialite format). Additionally `layer.getData(pixel)` is used to change the mouse pointer when hovering a non-transparent pixel on the map.

##### main.js

    import Map from 'ol/Map.js';
    import View from 'ol/View.js';
    import ImageLayer from 'ol/layer/Image.js';
    import ImageWMS from 'ol/source/ImageWMS.js';

    const wmsSource = new ImageWMS({
      url: '/cgi-bin/mapserv.exe?MAP=/ms4w/apps/openlayers-10.9.0/en/latest/examples/map/wms-server.map',
      params: {'LAYERS': 'countries'},
      serverType: 'mapserver',
      crossOrigin: 'anonymous',
    });

    const wmsLayer = new ImageLayer({
      source: wmsSource,
    });

    const view = new View({
      center: [0, 0],
      zoom: 1,
    });

    const map = new Map({
      layers: [wmsLayer],
      target: 'map',
      view: view,
    });

    map.on('singleclick', function (evt) {
      document.getElementById('info').innerHTML = '';
      const viewResolution = view.getResolution();
      const url = wmsSource.getFeatureInfoUrl(
        evt.coordinate,
        viewResolution,
        'EPSG:3857',
        {'INFO_FORMAT': 'text/plain'},
      );
      if (url) {
        fetch(url)
          .then((response) => response.text())
          .then((html) => {
            document.getElementById('info').innerHTML = html;
          });
      }
    });

    map.on('pointermove', function (evt) {
      if (evt.dragging) {
        return;
      }
      const data = wmsLayer.getData(evt.pixel);
      const hit = data && data[3] > 0; // transparent pixels have zero for data[3]
      map.getTargetElement().style.cursor = hit ? 'pointer' : '';
    });

##### index.html

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="UTF-8">
        <title>WMS GetFeatureInfo (local MS4W layer)</title>
        <link rel="stylesheet" href="node_modules/ol/ol.css">
        <style>
          .map {
            width: 100%;
            height: 400px;
          }
        </style>
      </head>
      <body>
        <div id="map" class="map"></div>
        <div id="info">&nbsp;</div>

        <script type="module" src="main.js"></script>
      </body>
    </html>

##### package.json

    {
      "name": "getfeatureinfo-image",
      "dependencies": {
        "ol": "10.9.0"
      },
      "devDependencies": {
        "vite": "^3.2.3"
      },
      "scripts": {
        "start": "vite",
        "build": "vite build"
      }
    }