Get sheet name with url by getting range from a cell

Length of undefined means that your links is undefined. Check the below script for a sample working code:

Script:

function getFileNames() {
  var sheet = SpreadsheetApp.getActive().getSheetByName("Links");
  var links = sheet.getRange("B3:B").getValues();

  // 1st: get a 1D array representation of the links (flat)
  // 2nd: remove the empty rows (filter)
  // 3rd: return the spreadsheet names of the remaining rows to filenames
  var filenames = links.flat().filter(String).map(link => {
    return [SpreadsheetApp.openByUrl(link).getName()];
  });

  var startRow = 3; // data will start at 3rd row
  var fileNameColumn = 3; // data will be written at 3rd column which is column C
  sheet.getRange(startRow, fileNameColumn, filenames.length, filenames[0].length)
       .setValues(filenames);
}

Output:

output