0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

chrome拡張機能 現在のタブのタイトルとURLを取得

Last updated at Posted at 2024-09-28

公開しているchrome拡張機能をManifestV3に対応するためバージョンアップ作業をしている際に、現在のタブのタイトルとURLを取得するために使用していたchrome.tabs.getSelectedが動かなくなっていて苦戦したのでメモ

旧バージョン

chrome.tabs.getSelected(null, function(tab) {  
  let Data = {"Title": "", "URL": ""}; 
  
  Data.Title = tab.title; 
  Data.URL = tab.url;

修正したバージョン

chrome.tabs.query({active:true, lastFocusedWindow:true}, tabs => {  
  let Data = {"Title": "", "URL": ""}; 
  
  Data.Title = tabs[0].title; 
  Data.URL = tabs[0].url;

tabs.queryを使うと出来るようになる

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?